[英]NGINX file not found for php files
I have the following setup. 我有以下设置。
Nginx as a web server. Nginx作为Web服务器。 Passing request to unicorn which runs as my ruby on rails server.
将请求传递给作为我在Rails服务器上的红宝石运行的独角兽。 I now want to install wordpress at mysite.com/blog.
我现在想在mysite.com/blog上安装wordpress。 I therefore have installed and configured php and fastcgi.
因此,我已经安装并配置了php和fastcgi。 The nginx config is as follows:
Nginx配置如下:
upstream unicorn_mysite {
server unix:/tmp/unicorn.mysite.sock fail_timeout=0;
}
server {
listen 80;
server_name mysite.com;
return 301 https://www.$server_name$request_uri;
}
server {
listen 443 ssl;
ssl_certificate /opt/certs/thinbundle.crt;
ssl_certificate_key /opt/certs/mysite.key;
server_name mysite.com;
root /opt/www/mysite/current/public;
location /blog {
index index.php;
if (!-e $request_filename) {
rewrite ^(.*)$ /blog/index.php?q=$1 last;
}
location ~ .php(?|$) {
include /etc/nginx/fastcgi_params;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /opt/www/mysite_wordpress$fastcgi_script_name;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
}
location ~ ^/assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}
try_files $uri/index.html $uri @unicorn;
location @unicorn {
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect off;
proxy_pass http://unicorn_mysite;
proxy_set_header X-Forwarded-Proto $scheme;
add_header Front-End-Htps on;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 10;
}
and the fastcgi_params file in /etc/nginx/fastcgi_params contains: / etc / nginx / fastcgi_params中的fastcgi_params文件包含:
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REQUEST_SCHEME $scheme;
fastcgi_param HTTPS $https if_not_empty;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;
When I go to mysite.com/blog I get this : 当我访问mysite.com/blog时,得到以下信息:
When I look at the nginx logs I see: 当我查看nginx日志时,我看到:
2016/03/15 11:26:35 [error] 23109#23109: *29 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 185.14.209.183, server: mysite.com, request: "GET /blog HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "www.mysite.com"
2016/03/15 11:28:36 [error] 23109#23109: *35 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 185.14.209.183, server: mysite.com, request: "GET /blog HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "www.mysite.com"
2016/03/15 11:32:12 [error] 23109#23109: *38 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 185.14.209.183, server: mysite.com, request: "GET /blog HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "www.mysite.com"
2016/03/15 11:36:41 [error] 23109#23109: *45 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 185.14.209.183, server: mysite.com, request: "GET /blog HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "www.mysite.com"
Can somebody please help me fix this File not found. 有人可以帮我解决找不到此文件的问题。 Which file is not found?
找不到哪个文件? and where is it looking for it - ie why can't it find it!
它在哪里寻找它-即为什么找不到它! None of these errors help me identify the cause of the issue!
这些错误均不能帮助我确定问题的原因!
Turns out the answer was because of this : 原来的答案是因为这样的:
http://web.archive.org/web/20141105045103/http://www.linux-support.com/cms-xxx/ubuntu-developers-thomas-ward-nginx-changes-in-debian-causing-default-config-fastcgi-users-issues http://web.archive.org/web/20141105045103/http://www.linux-support.com/cms-xxx/ubuntu-developers-thomas-ward-nginx-changes-in-debian-causing-default- config-fastcgi-users-issues
basically in my nginx config file I was pointing to /etc/nginx/fastcgi_params instead of the correct file /etc/nginx/fastcgi.conf. 基本上在我的nginx配置文件中,我指向的是/ etc / nginx / fastcgi_params而不是正确的文件/etc/nginx/fastcgi.conf。 Both of these files existed in my nginx install - so this was not easy to find or workout that we should be using fastcgi.conf.
这两个文件都存在于我的nginx安装中-因此我们不应该轻易找到或尝试使用fastcgi.conf进行查找。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.