【发布时间】:2021-04-25 02:01:49
【问题描述】:
这是我的 nginx 设置。而且我使用 Docker 和 Docker-Compose 来运行我的 nginx 和 web 服务
这是我在 docker 内运行 nginx -V 时看到的
nginx版本:nginx/1.15.5 由 gcc 6.4.0 (Alpine 6.4.0) 构建 使用 OpenSSL 1.0.2p 构建 2018 年 8 月 14 日 启用 TLS SNI 支持
## for http version of *
server {
listen 80;
listen [::]:80;
server_name domain_1 domain_2;
# Redirect all HTTP requests to HTTPS with a 301 Moved Permanently response.
return 301 https://$host$request_uri;
}
## for https version of *
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name domain_1;
location /websocket/ {
proxy_pass http://websocket:8001;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_redirect off;
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-Host $server_name;
}
## this is to proxy pass to the django container
location / {
proxy_pass http://django:5000;
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_redirect off;
}
location /websockets/ {
try_files $uri @proxy_websocket;
}
location @proxy_websocket {
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_redirect off;
proxy_pass http://websocket:8001;
}
## this is to alias the /static to the /staticfiles folder inside django container
location /static/ {
alias /django/staticfiles/;
}
## this is to alias the /media to the /media folder inside django container
location /media/ {
alias /django/media/;
}
## this is for the various SSL settings
include /etc/nginx/conf.d/ssl_common.conf;
# include /etc/nginx/conf.d/ssl_enp.conf;
ssl_certificate /etc/internal_trust/live/domain_1/domain_1.crt;
ssl_certificate_key /etc/internal_trust/live/domain_1/domain_1.key;
}
# for *.sg
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name domain_2;
location /websocket/ {
proxy_pass http://websocket:8001;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_redirect off;
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-Host $server_name;
}
## this is to proxy pass to the django container
location / {
proxy_pass http://django:5000;
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_redirect off;
}
location /websockets/ {
try_files $uri @proxy_websocket;
}
location @proxy_websocket {
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_redirect off;
proxy_pass http://websocket:8001;
}
## this is to alias the /static to the /staticfiles folder inside django container
location /static/ {
alias /django/staticfiles/;
}
## this is to alias the /media to the /media folder inside django container
location /media/ {
alias /django/media/;
}
## this is for the various SSL settings
ssl_certificate /etc/internal_trust/live/domain_2/domain_2.crt;
ssl_certificate_key /etc/internal_trust/live/domain_2/domain_2.key;
}
## this is to block attempts by those using invalid host headers
server {
server_name _;
listen 80 default_server;
# we do not need to cater for ssl 443 for invalid host headers
return 444;
}
但由于某种原因,即使我访问了 domain_2,正在检索的证书也始终是 domain_1 的证书。
我不确定我哪里出错了。
domain_1 运行良好
【问题讨论】:
-
从你的问题看来,我与 docker 无关
-
我看到有人要求关闭它,因为有人认为将其置于服务器故障下更正确。在这种情况下,请保持一致并要求关闭其他 SO 问题,例如 stackoverflow.com/questions/34278909/…
-
我还检查了meta.stackoverflow.com/a/261747/80353,这似乎是一个灰色区域,但如果它们不是生产环境,则共识提示将这些问题保留在此处。然后我的回答是,这是用于暂存和暂存域。