我有以下设置。
Nginx作为Web服务器。将请求传递给在rails服务器上作为我的ruby运行的独角兽。我现在想在mysite.com/blog上安装wordpress。因此我安装并配置了php和fastcgi。 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;
}
和/ 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;
当我去mysite.com/blog时,我得到了这个:
当我查看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"
有人可以帮我修复此文件未找到。找不到哪个文件?它在哪里寻找它 - 也就是为什么它找不到它!这些错误都不能帮助我找出问题的原因!
答案 0 :(得分:0)
原因是答案是因为:
基本上在我的nginx配置文件中,我指向/ etc / nginx / fastcgi_params而不是正确的文件/etc/nginx/fastcgi.conf。这两个文件都存在于我的nginx安装中 - 所以我们应该使用fastcgi.conf来查找或训练这些文件并不容易。