skip to Main Content

I have a lemp server on docker:

  • mysql container
  • php container
  • reverse proxy container
  • and then for each website a nginx container that have their own files of the website

so each website container have their own .conf file and from the reverse proxy container i can curl http://container1 and i have the website , the same for website2. however if i do this from the server os or on the browser i have the response that the server is not giving response.

this is my reverse proxy .conf:

server {
    listen 80;
    server_name container1.com;
    location / {
        proxy_pass http://container1.com;
        proxy_buffering 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-Proto $scheme;
    }
}

server {
    listen 80;
    server_name container2.com;
    location / {
        proxy_pass http://container2.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;
        proxy_buffering off;
    }
} 

container1.com is the name of the website container.
i think this should be working however i am getting this
curl http://website1.com
error code: 521

thanks in advance!

I have try to have only one website and i am getting the same answer, inside the website1.com curl http://localhost and http://website1.com returns the page, inside the reverse proxy also. so it means the comunication between reverse proxy container and the website container are working, but then from the web or the server os have this error 521 that means no server response

2

Answers


  1. Chosen as BEST ANSWER

    actually the answer was simpler than i thought, i had just one line too much, and this way already works perfectly

    server {
        listen 80;
        server_name container1.com;
        location / {
            proxy_pass http://container1.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;
        }
    }
    

  2. Your reverse proxy configuration seems to have a typo at the proxy_pass directive line in both cases. You use the server name "container1.com", instead of the container name "container1".

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search