在Docker中运行WEB应用,由主机Nginx反向代理。由于Docker中的应用是http,而反向代理强制使用https,会遇到有些情况代理失败。
只要在配置中加上
proxy_set_header X-Forwarded-Proto https;
完整配置:
server {
listen 80;
listen [::]:80;
server_name engr-z.com www.engr-z.com;
# enforce https
return 301 https://$server_name:443$request_uri;
}
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name engr-z.com www.engr-z.com;
client_max_body_size 1G;
ssl_certificate /data/www/cert/engr-z.com_nginx/cert.pem;
ssl_certificate_key /data/www/cert/engr-z.com_nginx/cert.key;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; #使用此加密套件。
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; #使用该协议进行配置。
ssl_prefer_server_ciphers on;
location / {
proxy_pass http://127.0.0.1:8001/;
proxy_set_header Host $host;
proxy_set_header X-Real-Ip $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Proto https;
# proxy_cookie_path / /;
}
}
发表回复