Home > Backend Development > PHP Tutorial > 自定义Nginx配置不成功,为何?

自定义Nginx配置不成功,为何?

WBOY
Release: 2016-06-06 20:41:08
Original
1140 people have browsed it

原先我在apache中的配置如下:

<code class="lang-apache">RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
</code>
Copy after login
Copy after login

作用:如果URL所指向的文件在服务器目录中不存在,则将URL全指向index.php中。

结构我是按文档中自定义Nginx配置中描述所建,Nginx我不太会用了个配置转换工具得到在Nginx中的配置:

<code class="lang-nginx"># nginx configuration
location / {
    if (!-e $request_filename){
        rewrite ^(.*)$ /index.php break;
    }
}
</code>
Copy after login
Copy after login

但放到云景的PHP空间的conf/nginx_server.inc文件中后空间就无法打开了,想问下为啥!

回复内容:

原先我在apache中的配置如下:

<code class="lang-apache">RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
</code>
Copy after login
Copy after login

作用:如果URL所指向的文件在服务器目录中不存在,则将URL全指向index.php中。

结构我是按文档中自定义Nginx配置中描述所建,Nginx我不太会用了个配置转换工具得到在Nginx中的配置:

<code class="lang-nginx"># nginx configuration
location / {
    if (!-e $request_filename){
        rewrite ^(.*)$ /index.php break;
    }
}
</code>
Copy after login
Copy after login

但放到云景的PHP空间的conf/nginx_server.inc文件中后空间就无法打开了,想问下为啥!

这个问题算是解决了,最终我还是在slimphp项目的readme中找到了解决方法,如下:

<code>location / {
    try_files $uri $uri/ /index.php?$args;
    root /opt/src/app;
}
</code>
Copy after login

再对PHP也做了点设置:

<code>location ~ \.php$ {
    root /opt/src/app;
    fastcgi_pass 127.0.0.1:8080;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME /opt/src/app/$fastcgi_script_name;
    include /opt/apps/nginx/conf/fastcgi_params;
}
</code>
Copy after login

http://cloudscape.sohu.com/doc/operation/app-conf.shtml
参考文档中的标题6,自定义Nginx配置部分

nginx的自定义配置可能与您的项目整体配置有冲突,可以登录到容器上查看相关配置,修改下配置试试看。

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template