我对这个感到很恼火。
你可以在这里看到自己——http://starterpad.com/blog/- 所有图像、CSS 和 JS 文件都是 404 错误。
StarterPad 主站点 (http://starterpad.com) 运行的是 Rails,看上去还不错。但 /blog 是 WordPress,而且它已经过时了。
这是我们的 nginx.conf 文件:
user apache;
worker_processes 2;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
passenger_root /usr/local/rvm/gems/ruby-2.0.0-p247/gems/passenger-4.0.24;
passenger_ruby /usr/local/rvm/wrappers/ruby-2.0.0-p247/ruby;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
reset_timedout_connection on;
keepalive_timeout 65;
gzip on;
# include /etc/nginx/conf.d/*.conf;
server {
server_name www.starterpad.com;
return 301 $scheme://starterpad.com$request_uri;
}
upstream starterpad {
server unix:///var/www/starterpad.com/shared/tmp/sockets/puma.sock fail_timeout=0;
}
server {
listen 80;
server_name starterpad.com vps.starterpad.com;
root /var/www/starterpad.com/current/public;
error_log /var/www/starterpad.com/shared/log/nginx_error.log;
access_log off;
error_page 403 404 /404.html;
error_page 422 /422.html;
error_page 500 502 503 504 /500.html;
location ^~ /assets|uploads/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}
location @starterpad {
proxy_pass http://starterpad; # match the name of upstream directive which is defined above
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location / {
try_files /index.html $uri.html $uri @starterpad;
}
location /blog/ {
#try_files $uri $uri/ /blog/index.php?$args;
#deny all;
root /var/www/starterpad.com/blog;
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
include wpsecure.conf;
index index.php;
try_files $uri $uri/ /index.php?q=$uri&$args;
}
location ~ \.php {
root /var/www/starterpad.com/blog;
try_files $uri = 404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
}
这是错误日志中的一些错误,但它们对我来说似乎没有帮助:
2015/01/26 22:16:06 [错误] 11511#0: *11 open() "/var/www/starterpad.com/blog/blog/wp-content/themes/sparkling/inc/css/font-awesome.min.css" 失败 (2: 没有此文件或目录), 客户端: 173.245.48.128, 服务器: starterpad.com, 请求: "GET /blog/wp-content/themes/sparkling/inc/css/font-awesome.min.css?ver=4.1 HTTP/1.1", 主机: "starterpad.com", 引用者: "http://starterpad.com/blog/“
2015/01/26 19:22:26 [错误] 10431#0:*28798 FastCGI 在 stderr 中发送:“无法打开主脚本:/var/www/starterpad.com/blog/b6d767d2f8ed5d21a44b0e5886680cb9/generator.php(没有此文件或目录)”在从上游读取响应标头时,客户端:108.162.215.123,服务器:starterpad.com,请求:“POST /b6d767d2f8ed5d21a44b0e5886680cb9/generator.php HTTP/1.1”,上游:“fastcgi://127.0.0.1:9000”,主机:“starterpad.com”,引荐来源:“http://starterpad.com/blog/wp-content/uploads/2014/12/SoftwareProgrammer-750x410.jpg“
我已阅读了很多 Stack Overflow 和其他页面,尝试了 nginx.conf 中的几乎所有方法,但我无论如何都无法让它工作。
有什么想法吗?你会成为我心目中的英雄!
答案1
搞清楚了(感谢迈克尔·汉普顿)。更改的行在下面以粗体显示。
位置 /博客/ {
根目录/var/www/starterpad.com;
包括 wpsecure.conf;
索引 index.php;
try_files $uri $uri/ /index.php?q=$uri&$args;
}
位置 ~ .php$ {
root /var/www/starterpad.com/blog;
try_files $uri $uri/ /index.php?q=$uri&$args;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+.php)(.*)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
包括 fastcgi_params;
}