【发布时间】:2017-08-11 21:42:17
【问题描述】:
我有一个 WordPress Docker 容器,并在主机上使用 nginx 作为反向代理。
在 32776 端口上为 WordPress 提供服务的 WP 容器和我的 nginx 配置在主机上是这样的:
nginx 配置(主机)
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
...
location /blog {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:32776;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
...
}
Docker 内部的 nginx 配置
server {
listen 0.0.0.0:80 default_server;
listen [::]:80 default_server;
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.php index.html index.htm;
server_name _;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
error_log ... error;
access_log ...;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
当我浏览到 domain.com/blog 时,它可以工作,但没有样式和 javascript 文件。因为当我转到 domain.com/blog/wp-content/themes/twentyseventeen/style.css 时,它会自动重定向到 domain.com/blog/wp-content/themes/twentyseventeen/ style.css/ 并根据我的访问日志,它试图找到 domain.com/blog/wp-content/themes/twentyseventeen/style.css/index.php
如何正确设置我的 Nginx 配置文件?
【问题讨论】: