【发布时间】:2021-05-21 14:32:29
【问题描述】:
我正在建立一个 WordPress 网站供自己使用。我正在尝试使用 Nginx 作为 SSL 反向代理,就像我运行的其他 Webtools 一样。我有三个 Linux 容器:
- 10.0.0.51:443:五个 Web 工具 + 一个 WordPress 站点的 Nginx SSL 代理
- 10.0.0.52:Web 工具容器,工具使用 HTTP 在各种端口上运行
- 10.0.0.164:8080:适用于 WordPress 的 Apache
我正在使用 Let's Encrypt 提供 SSL 证书,这很好用。我的 Webtools 可以正常工作,并且它们都有自己的子域。 WordPress 网站应该位于www.example.org。当我转到这个 URL 时,我被重定向到 https://www.example.org:8080,这显然给了我一个超时。另一方面,当我访问http://10.0.0.164:8080 时,WordPress 站点确实可以正确加载。听起来 Apache 正在重写 URL 以包含 :8080?
我的 Nginx 站点配置如下:
server {
server_name www.example.org;
location / {
proxy_pass http://10.0.0.164:8080;
include /etc/nginx/proxy_params;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/www.example.org/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/www.example.org/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = www.example.org) {
return 301 https://$host$request_uri;
} # managed by Certbot
server_name www.example.org;
listen 80;
return 404; # managed by Certbot
}
Nginx 代理参数:
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Server $host;
和 Apache VirtualHost 配置。其余为默认值:
<VirtualHost *:8080>
ServerName domain.org
ServerAlias www.example.org
ServerAdmin webmaster@localhost
DocumentRoot /var/www/example.org
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
# Allow .htaccess overwrites
<Directory /var/www/example.org/>
AllowOverride All
</Directory>
【问题讨论】: