我有一台服务器上有一个 Django 项目和一个 Wordpress 博客,我使用 Nginx 从本地端口(GUnicorn 为 8001,Apache 为 8081)为这两个域提供服务
我为我的 wordpress 网站设置了以下 Nginx 文件,但我只能访问主页。所有其他页面都是 502。我不明白我错过了什么!
Nginx:Nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
sendfile on;
gzip on;
gzip_http_version 1.0;
gzip_proxied any;
gzip_min_length 500;
gzip_disable "MSIE [1-6]\.";
gzip_types text/plain text/xml text/css
text/comma-separated-values
text/javascript
application/x-javascript
application/atom+xml;
# Configuration for Nginx
server_names_hash_bucket_size 64;
server {
return 404;
}
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
wordpress配置文件
# WordPress single site rules.
# Designed to be included in any server {} block.
# Upstream to abstract backend connection(s) for php
upstream php {
#server unix:/tmp/php-cgi.socket;
server 127.0.0.1:8081;
}
server {
## Your website name goes here.
server_name www.simple-ripple.com simple-ripple.com;
## Your only path reference.
root /var/www;
## This should be in your http block and if it is, it's not needed here.
index index.php;
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location / {
# This is cool because no php is touched for static content.
# include the "?$args" part so non-default permalinks doesn't break when using query string
try_files $uri $uri/ /index.php?q=$uri$args;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header HOST $http_host;
proxy_set_header X-NginX-Proxy true;
include proxy_params;
proxy_pass http://127.0.0.1:8081;
}
location ~ \.php$ {
#NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
#fastcgi_split_path_info ^(/wp)(/.*)$;
include fastcgi.conf;
fastcgi_intercept_errors on;
fastcgi_pass php;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
}
#location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
# expires max;
# log_not_found off;
#}
}
答案1
为了扩展我对您的问题的评论,请在 wordpress 和 php-fpm 下为您的 vhost 使用类似的配置
location / {
index index.php index.html;
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass_header Set-Cookie;
fastcgi_pass_header Cookie;
fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
fastcgi_pass YOURBACKEND;
fastcgi_index index.php;
include fastcgi.conf;
}