Ghost installed on Docker cannot be accessed after URL is configured with environment variable, “Too many redirections”

  docker, question

Environment: Nginx (with SSL)+Docker+Ghost

The Docker container runtime is configured with an environment variable -e URL=xxx

Nginx configuration:

server {
 listen 443 ssl http2;
 ssl on;
 server_name xxxxx.xxx;
 ssl_certificate /etc/nginx/ssl/*.xxxxx.xxx.cer;
 ssl_certificate_key /etc/nginx/ssl/*.xxxxx.xxx.key;
 add_header Strict-Transport-Security max-age=31536000;
 location / {
 proxy_set_header    X-Real-IP   $remote_addr;
 proxy_set_header    Host              $http_host;
 proxy_pass         http://127.0.0.1:80xx;
 }
 }
 server {
 listen 80;
 server_name xxxxx.xxx;
 add_header Strict-Transport-Security max-age=31536000;
 return 301 https://xxxxx.xxx$request_uri;
 }

Phenomena: Chrome prompt redirects too many times, closing Docker container to display 502 Bad Gateway

No additional environment variables are normal.

Recently in the buildingGhostWhen blogging, because of the use ofNginxNot under my control, so I also encountered this use.httpsThe problem of “too many redirections” (url changed tohttpThere is no problem); After searching, we got the answer:X-Forwarded-ProtoForSSLEspecially important. Therefore, when using Nginx or Apache as a proxy, it needs to be configured. If you use Nginx, you can configure it as follows:

location / {
 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_pass http://127.0.0.1:2368;
 }

Reference: