首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >达到API的NGINX服务器指令

达到API的NGINX服务器指令
EN

Stack Overflow用户
提问于 2016-03-14 22:13:35
回答 1查看 212关注 0票数 1

我有一个LEMP服务器,我希望安装RespondCMS (http://respondcms.com/documentation/install-on-digital-ocean)。我在API的mod_rewrite部分遇到了一些困难。我尝试过几次迭代,但无法让它显示"API工作“消息,表明PHP应用程序正在工作。我得到404分。到目前为止,我已经确定了以下设置-在我的/etc/nginx/站点-启用/。我认为它没有正确地访问/api文件夹。任何帮助理解它是如何相互作用和如何使它工作是值得赞赏的。

代码语言:javascript
复制
app.domain.com
server {
    listen 80;
    server_name app.domain.com;

    root /srv/www/domain_app/app;
    index index.php index.html index.htm;

    access_log /var/log/nginx/respond.access.log;
    error_log /var/log/nginx/respond.error.log;


    location /api/ {
            try_files $uri $uri/ /api/dispatch.php$args;
    }

    location / {
            try_files $uri $uri/ =404;

    }

    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
            root /srv/www;
    }

    location ~ \.php$ {
            try_files $uri =404;
            include fastcgi_params;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

}





domain.com
server {
    listen 80 default_server;

    root /srv/www/html;
    index index.php index.html index.htm;

    server_name domain.com;

    location / {
            try_files $uri $uri/ =404;
    }

    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
            root /usr/share/nginx/html;
    }

    location ~ \.php$ {
            try_files $uri =404;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            include fastcgi_params;
    }

}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-03-17 08:09:59

URL http://app.domain.com/api/dispatch.phplocation ~ \.(hh|php)$块处理。该块似乎被正确地配置(合理)。

您应该将include fastcgi_params;移至任何fastcgi_param指令之上,以避免后者被无意中覆盖。在这种情况下,fastcgi_index指令是多余的。

location /location /api/块都有问题。alias指令是不必要的,也是错误的。所有三个位置都从外部root块继承它们的server。您应该删除这两个alias指令。

try_files $uri $uri/ $uri.php /api/dispatch.php$args;语句中,$uri.php元素将导致下载而不是执行PHP文件。只有try_files指令的最后一个元素才能执行未在同一位置块中处理的操作。如果您确实需要执行没有扩展的PHP,并且也有一个默认的PHP,那么您可能需要使用一个指定的位置。

对于所有nginx指令来说,一个有用的资源是这里

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35999114

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档