我正在尝试使用以下配置将Nginx作为反向代理设置Wordpress(在php-fpm中运行)。
我已经在/var/www/public/blog
中安装了wordpress。
root@1088e33c9d2d:/srv# ls /var/www/public/blog/
index.php readme.html wp-admin wp-comments-post.php wp-config-sample.php wp-cron.php wp-links-opml.php wp-login.php wp-settings.php wp-trackback.php
license.txt wp-activate.php wp-blog-header.php wp-config.php wp-content wp-includes wp-load.php wp-mail.php wp-signup.php xmlrpc.php
Nginx.conf,
server {
server_name _;
listen 80 default_server;
listen [::]:80 default_server;
access_log syslog:server=unix:/dev/log;
error_log syslog:server=unix:/dev/log debug;
root /var/www/public;
# Default location settings
location / {
index index.html index.htm index.php;
}
location /blog {
index index.html index.htm index.php;
try_files $uri $uri/ /blog/index.php?$args;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
# Set expires time for browser caching for media files
location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
access_log off;
log_not_found off;
expires max;
}
# Set expires time for js and css files
location ~* \.(js|css)$ {
expires 24h;
add_header Pragma public;
add_header Cache-Control "public";
log_not_found off;
}
# Block serving of hidden files
location ~ /\. {
deny all;
access_log off;
log_not_found off;
}
location ~ /\.ht {
deny all;
}
location ~ /.well-known {
allow all;
}
location = /robots.txt { log_not_found off; access_log off; allow all; }
location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
expires max;
log_not_found off;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# Remove the annoying favicon request in logs
location = /favicon.ico {
return 204;
access_log off;
log_not_found off;
}
# Health check for Kubernetes readiness probe
location /healthz {
access_log off;
return 200;
}
}
但是,导航到http://localhost/blog
会立即使我先后依次302
和404
重定向到http://localhost/wp-admin/install.php
。
如果我确实导航到http://localhost/blog/wp-admin/install.php
,则会显示安装页面,但是404
会丢失所有静态内容。他们都指向http://localhost/wp-content
等。
wordpress_1 | Jul 31 11:14:31 dbb622bd110b dbb622bd110b nginx: 192.168.32.1 - - [31/Jul/2018:11:14:31 +0200] "GET /blog/ HTTP/1.1" 302 5 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:61.0) Gecko/20100101 Firefox/61.0"
wordpress_1 | Jul 31 11:14:31 dbb622bd110b dbb622bd110b nginx: 192.168.32.1 - - [31/Jul/2018:11:14:31 +0200] "GET /wp-admin/install.php HTTP/1.1" 404 169 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:61.0) Gecko/20100101 Firefox/61.0"
有人能指出我正确的方向吗?不知道为什么上面的Nginx配置错误。