I'm setting up the reverse proxy with Docker and Nginx.
I used the page https://example.org/
for an example.
I set up the custom domain with local mapping in
/etc/hosts
127.0.0.1 example.org
I set up the docker-compose file as below
version: '3'
services:
nginx:
image: nginx:latest
container_name: nginx-reverse-proxy
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
- ./nginx-selfsigned.crt:/etc/nginx/nginx-selfsigned.crt
- ./nginx-selfsigned.key:/etc/nginx/nginx-selfsigned.key
ports:
- 80:80
- 443:443
- Then I set up the
nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80 default_server;
listen 443 ssl;
ssl_certificate nginx-selfsigned.crt;
ssl_certificate_key nginx-selfsigned.key;
server_name example.org;
add_header Last-Modified $date_gmt;
proxy_cache_bypass 1;
location / {
add_header X-Upstream 'default docker' always;
proxy_pass https://example.org;
proxy_ssl_server_name on;
}
}
include servers/*;
}
But after I run docker compose up
Then I access the page https://example.org
I got 502 bad gateway
error with a lot of headers X-Upstream: default docker
added which I configured
I don't know which one is wrong in the configuration :(
UPDATED:
I'm not finding out the issue yet.
I decided to go with proxy_pass https://ip_address
rather than with the domain name. I don't understand why it work with nginx on local machine but not with nginx in docker