我有一个Nginx服务器:exmaple.com 在同一台服务器上,代理设置为:d1.example.com
现在我需要在同一个 d1.example.com
上附加SSL注意:我拥有的SSL证书包含Common Name: www.d1.example.com
我的Nginx配置:
server {
listen 8443 default;
server_name www.example.com;
root /Data/html;
.....
.....
}
//Added
server {
listen 443;
server_name d1.example.com;
ssl on;
ssl_certificate /etc/ssl/certs/www_s1_example_com.crt;
ssl_certificate_key /etc/ssl/certs/example_com.key;
location / {
proxy_pass http://d1.example.com;
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_set_header X-Forwarded-Proto $scheme;
}
}
//Added
server {
listen 80;
server_name d1.example.com;
location / {
proxy_pass http://d1.example.com;
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_set_header X-Forwarded-Proto $scheme;
}
}
注意:我的第三个服务器块正在成功处理http://d1.exmaple.com的请求并显示正确的网址。第一个服务器块正在处理https://example.com的请求。 但对于SSL即https://d1.exmaple.com的情况,网址被重定向到https://exmaple.com
感谢任何帮助。