微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在nginx中找不到位置块

Nginxconfiguration中试图找出位置块很困难。 这是我的:

server { listen 80; server_name _; access_log /var/log/Nginx/example.com.access_log; error_log /var/log/Nginx/example.com.error_log warn; root /var/www/root; index index.PHP index.htm index.html; fastcgi_index index.PHP; location /wp/ { root /var/www/wordpress; index index.PHP index.htm index.html; fastcgi_index index.PHP; } location ~* .PHP$ { try_files $uri =404; keepalive_timeout 0; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_pass 127.0.0.1:9000; } }

浏览/按预期工作,并在/ var / www / root中显示网站,但是如果位置工作,我认为他们应该浏览到/ WP应带我到/ var / www / wordpress中的wordpress安装。 我所得到的是:

404没有find

Nginx的/ 0.7.67

编译标志与configuration选项 – TLS心跳

如果“NULL”,那么在shell脚本中使用0

如何在post请求Nginx删除结尾的斜线

在Windows中使用mongodb.config设置mongodbconfigurationpath

如何在docker实例中closuressendfile

如果我将/ var / www / wordpress目录重定位到/ var / www / root / wordpress并浏览到/ wordpress,那么这是完美的。

我在做什么错位置块?

我从来没有configuration过Nginx,而且是一个完整的web newb。

我希望能够为其他应用程序提供更多的位置块。 这真的只是在这里张贴的一个基本的例子。

在Debian Squeeze backports中将Nginx更新为版本。 没提升:

404没有find

Nginx的/ 1.1.19

如何通过configuration生成libtool自定义脚本?

sqlcipher ./configuration linux

如何使用最less的代码行将C结构存储在可读的文件中?

我如何让PHP curl在我的apache2.x开发服务器上运行?

在不同的Windows上无法识别的属性“multipleSiteBindingsEnabled”问题

它不工作的原因是…

在服务器级别,你有“root / var / www / root”。 所以基本上,每个位置块将使用这个,除非特别重写。 这是很好的做法。

然后你可以在“wp”位置块中将其覆盖到“/ var / www / wordpress”。 但是,PHP位置块仍然使用认值。

现在,当您向“/var/www/wordpress/folder_a/file_a.PHP”物理位置的“/wp/folder_a/file_a.PHP”发出请求时,该请求会触发PHP位置块并提供根文件夹主动为该块去查找“/var/www/root/folder_a/file_a.PHP”中的文件。 结果,你得到了“404找不到”。

您可以将服务器级别的根指令更改为“/ var / www / wordpress”,并删除wp位置中的覆盖。 这将解决这个问题,但“/ var / www / root”下的PHP脚本将不再起作用。 不知道你有没有。

如果你需要在“/ var / www / root”和“/ var / www / wordpress”下运行PHP,你需要这样做:

server { ... root /var/www/root; index index.PHP index.htm index.html; # Keep fastcgi directives together under location # so removed fastcgi_index # Put keepalive_timeout under 'http' section if possible location /wp/ { root /var/www/wordpress; # One appearance of 'index' under server block is sufficient location ~* .PHP$ { try_files $uri =404; fastcgi_index index.PHP; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_pass 127.0.0.1:9000; } } location ~* .PHP$ { try_files $uri =404; fastcgi_index index.PHP; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_pass 127.0.0.1:9000; } }

也就是说,在wp位置块下嵌套一个重复的PHP位置块。 它将继承wp的根指令。

为了让事情变得简单易行并且简化编辑等,你可以把fastcgi指令放到一个单独的文件中,并根据需要包含它。

所以在/path/fastcgi.params中,你有:

fastcgi_index index.PHP; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_pass 127.0.0.1:9000;

你的conf可以是:

server { ... root /var/www/root; ... location /wp/ { root /var/www/wordpress; location ~* .PHP$ { try_files $uri =404; include /path/fastcgi.params; } } location ~* .PHP$ { try_files $uri =404; include /path/fastcgi.params; } }

这样,如果您需要编辑任何fastcgi参数,只需在一个地方进行编辑即可。

PS。 更新你的Nginx将不会解决这个问题,因为它不是一个版本问题..但无论如何更新!

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐