I have a problem with configuring nginx in docker containers.

docker-compose.yml:

version: '3' services: nginx: build: ./nginx ports: - 80:80 - 443:443 links: - php php: build: ./php volumes: - ../domains:/var/www/html ports: - 82:80 depends_on: - db ... 

dockerfile for nginx:

 FROM nginx COPY nginx.conf /etc/nginx/nginx.conf 

nginx.conf:

 user www-data; worker_processes 1; events { worker_connections 1024; } http { server { listen 80; server_name local.test1.ru; root ../domains/test1.ru/; location / { proxy_pass http://php/test1.ru/; proxy_set_header Host $host; } } } 

when I follow the path: local.test1.ru/wp-admin , then it redirects me to local.test1.ru/test1.ru/wp-admin , although I have to stay on the old one. what could be the problem?

  • root - enter the absolute path - diproart
  • why not use php: 7-apache or php: 7-fpm right away? - diproart

1 answer 1

Need to turn off the redirect for proxy

 proxy_redirect off; # бонус, на что обратить внимание: # proxy_set_header X-Real-IP $remote_addr; # proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; # proxy_set_header Upgrade $http_upgrade; # proxy_set_header Connection "Upgrade"; # proxy_set_header X-Forwarded-Proto $scheme; # proxy_connect_timeout 60; # proxy_send_timeout 60; # proxy_read_timeout 60; 

example

 location / { # ... proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $http_host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_redirect off; proxy_pass http://php/test1.ru/; # ... } 

Since the configuration gets into the image at the build stage, you need to rebuild the image, for example, docker-compose up --build . You can mount the directory with the nginx configuration, so as not to re-compile the image each time it changes.

  • specified the absolute root path, turned off the redirect for the proxy - nothing has changed. the $ REQUEST_URL variable still gets the path /test1.ru/ for the query local.test1.ru/, although it should be / - Vlad
  • you need to rebuild the image - build / docker-compose up - build - diproart