我有一个设置,其中一个公共 Nginx 反向代理服务器后面有许多 Apache Web 服务器。但我无法从互联网访问网络服务器。该访问在我的本地网络上工作正常,因此我怀疑我的 Apache 设置是正确的。但我不能 100% 确定,因为尝试连接互联网会触发两条错误消息 - 一条来自 Nginx 服务器,一条来自 Apache 服务器。
Nginx 服务器报告以下错误:“在 SSL 握手时监听 SSL 端口的服务器中没有定义 ssl_certificate”,并且 Apache Web 服务器出现以下错误:“authz_core 错误 ... AH01630 客户端被服务器配置拒绝”。
Nginx 反向代理服务器的配置分为两个文件 - 一个用于 HTTP 流量,一个用于 HTTPS:
<example_dk_80.conf>:
server {
listen 80;
server_name example.dk www.example.dk;
return 301 https://$server_name$request_uri;
}
<example_dk_443.conf>:
server {
listen 443 ssl http2;
server_name example.dk www.example.dk;
add_header Strict-Transport-Security "max-age=31536000";
ssl on;
ssl_certificate /etc/ssl/certs/example_dk.crt;
ssl_certificate_key /etc/ssl/private/example_dk.key;
ssl_trusted_certificate /etc/ssl/certs/example_dk.ca-bundle;
ssl_protocols TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_session_cache shared:SSL:10m;
ssl_session_tickets off;
ssl_stapling on;
ssl_stapling_verify on;
resolver 172.16.1.10 8.8.8.8 8.8.4.4 valid=300s;
resolver_timeout 5s;
location /.well-known {
alias /var/www/example_dk/.well-known;
}
location / {
proxy_pass http://172.16.1.51:443;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
我的 Apache Web 服务器(带有 WordPress)配置如下:
<vhost.conf>:
DirectoryIndex index.php index.html
<VirtualHost *:80>
ServerName example.dk
ServerAlias www.example.dk
DocumentRoot "/var/www/example_dk"
<Directory "/var/www/example_dk">
AllowOverride All
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:443>
ServerName example.dk
ServerAlias www.example.dk
DocumentRoot "/var/www/example_dk"
SSLEngine on
SSLCipherSuite AES256+EECDH:AES256+EDH
SSLProtocol All -SSLv2 -SSLv3
SSLHonorCipherOrder On
SSLCompression off
SSLCertificateFile /etc/ssl/certs/example_dk.crt
SSLCertificateKeyFile /etc/ssl/private/example_dk.key
SSLCertificateChainFile /etc/ssl/certs/example_dk.ca-bundle
<Directory "/var/www/example_dk">
AllowOverride None
Options Indexes FollowSymLinks MultiViews
Require all granted
</Directory>
</VirtualHost>
我不知道这是否有什么不同,但这是我的 WordPress 安装的 htaccess 文件:
<.htaccess>:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
## Security
<Files xmlrpc.php>
Require all denied
</Files>
<Files wp-config.php>
Require all denied
</Files>
Options -Indexes
## SSL
#Header set Strict-Transport-Security "max-age=31536000" env=HTTPS
## Force www
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.dk [NC]
RewriteRule ^(.*)$ http://www.example.dk/$1 [L,R=301,NC]
## Force https
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
我所有的服务器都运行 Ubuntu 18.04。
答案1
proxy_pass http://172.16.1.51:443;
由于指定的协议是http://
这告诉 nginx 使用纯 HTTP 访问端口 443 的服务器。鉴于此端口上的服务器配置了 HTTPS,尽管这会失败。相反,要么应指定协议https://
在端口 443 上使用 HTTPS 访问服务器,要么应指定为http://
(默认)端口 80,以便在纯 HTTP 所需的端口上使用纯 HTTP 访问服务器。