Nginx在访问siteb.com/blog时抛出“未指定输入文件" [英] Nginx is throwing 'no input file specified' when accessing siteb.com/blog
问题描述
我已经看了好几个小时,但尽管花了很多时间在谷歌上搜索,但仍然无法到达我要去的地方.Nginx抛出了未指定输入文件
Ive looked at this for hours, but am still not getting where I need to get to despite doing a lot of hours googling.Nginx is throwing no input file specified
我的配置如下:
upstream site {
#flask app
server 127.0.0.1:8001;
}
upstream siteb-blog {
#wordpress php
server unix:/var/run/php5-fpm.sock;
}
server {
server_name siteb.com;
listen 80;
root /home/www/flask-deploy/siteb;
location ~* ^blog/ {
try_files $uri $uri/ /blog/index.php?$query_string;
root /home/www/flask-deploy/siteb-blog;
location ~ \.php$ {
fastcgi_pass siteb-blog;
fastcgi_param SCRIPT_FILENAME $request_filename;
include fastcgi_params;
}
}
location / {
try_files @proxy @proxy;
}
location @proxy {
internal;
proxy_pass http://siteb;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /static {
alias /home/www/flask-deploy/siteb/static/;
}
}
但是,当我尝试访问 mysite.com/blog
或 mysite.com/blog/info.php
时,出现404错误.
However, when i try to access mysite.com/blog
or mysite.com/blog/info.php
i get a 404 error.
ive检查了 error.log
,它没有显示任何错误. access.log
,仅显示:
ive checked error.log
and it doesnt show any errors. access.log
, just shows:
[16/Dec/2016:16:11:56 -0500] "GET /blog/index.php HTTP/1.1" 404 209 "-" "Mozilla/5.0 (X11; Ubuntu; Linux armv7l; rv:50.0) Gecko/20100101 Firefox/50.0"
我的 siteb.com
正常工作. siteb.com/blog
不会.
im专门尝试在 siteb.com/blog
上使 siteb-blog
工作.
im specifically trying to get siteb-blog
working at siteb.com/blog
.
提前谢谢!
推荐答案
您已将WordPress安装在名为 siteb-blog
的目录下,并希望使用/博客/
.您的问题之一是 $ request_filename
是由 root
和URI构造的,因此/blog
段成为路径名的一部分.有关详细信息,请参见本文档.
You have WordPress installed under a directory called siteb-blog
and would like to access it with a URI prefix of /blog/
. One of your problems is that the $request_filename
is constructed from the root
and URI, so that the /blog
segment becomes part of the pathname. See this document for details.
使用静态文件的简单解决方案是使用 alias
指令,但是由于
The simple solution with static files is to use the alias
directive, but I try to avoid using it with try_files
because of a long standing bug.
我的首选解决方案是静默地(使用内部重写)将/blog
URI映射到/siteb-blog
,然后继续使用 root
正常.
My preferred solution is to silently (using internal rewrite) map the /blog
URI to /siteb-blog
, then continue to use root
as normal.
例如:
server {
server_name siteb.com;
listen 80;
location /blog {
rewrite ^/blog(.*)$ /siteb-blog$1 last;
}
location /siteb-blog {
root /home/www/flask-deploy;
try_files $uri $uri/ /blog/index.php?$query_string;
location ~ \.php$ {
try_files $uri /blog/index.php;
fastcgi_pass siteb-blog;
fastcgi_param SCRIPT_FILENAME $request_filename;
include fastcgi_params;
}
}
location / {
proxy_pass http://siteb;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /static {
root /home/www/flask-deploy/siteb;
}
}
- 您可以通过添加
internal
指令使location/siteb-blog
内部.这将使其直接不可访问. -
server
块和location/static
块中的root
语句都是不必要的-它只需出现一次. - 不需要
alias
-首选root
.有关详细信息,请参见本文档. - 命名的位置是不必要的-与
location/
合并
- You can make the
location /siteb-blog
internal, by adding theinternal
directive. This will make it inaccessible directly. - A
root
statement in both theserver
block and thelocation /static
block is unnecessary - it only needs to appear once. - The
alias
was unnecessary -root
is preferred. See this document for details. - The named location was unnecessary - merged with
location /
最后,WordPress 需要知道它托管在/blog
下,否则它无法找到其资源文件(css和js).您将需要使用 wp-config.php
或使用WordPress⇒设置 WP_SITEURL
和 WP_HOME
的值.仪表板⇒设置⇒常规页面.
Finally, WordPress needs to know that it is hosted under /blog
, otherwise it cannot find its resource files (css & js). You will need to set the values for WP_SITEURL
and WP_HOME
either using wp-config.php
or using the WordPress ⇒ DashBoard ⇒ Settings ⇒ General page.
这篇关于Nginx在访问siteb.com/blog时抛出“未指定输入文件"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!