I'm newbie about NGINX, I'm trying to put two services inside the same Docker Container. Every services has his domain.
I found this answer that solve my problem but there is another problem that I'm not be able to solve.
If I use the default.conf
below, both services works fine:
server {
listen 80;
listen [::]:80;
#server_name domain.me www.domain.me;
server_name 127.0.0.1; # FOR STAGING ONLY
error_log /var/log/nginx/error.log warn;
access_log /var/log/nginx/access.log combined;
location / {
proxy_pass http://website:8301; # The port must be the same of PROJECT_PORT
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_redirect off;
# max uploadable file size
client_max_body_size 4G;
}
location /static/ {
# static folder on the server
alias /app/web/static-folder/;
}
location /media/ {
# media folder on the server
alias /app/web/media-folder/;
}
}
server {
#server_name geoserver.domain.me www.geoserver.domain.me;
server_name 127.0.0.2; # FOR STAGING ONLY
listen 80;
listen [::]:80;
server_tokens off;
root /usr/share/nginx/html;
index index.html;
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types
text/plain
text/css
application/json
application/javascript
application/x-javascript
text/xml application/xm
application/xml+rss
text/javascript;
underscores_in_headers on;
proxy_set_header HOST $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_buffering on;
proxy_buffer_size 1k;
proxy_buffers 24 4k;
proxy_busy_buffers_size 8k;
proxy_max_temp_file_size 2048m;
proxy_temp_file_write_size 32k;
location / {
deny all;
return 301 /geoserver;
}
location /geoserver {
proxy_pass http://geoserver:8080/geoserver;
}
}
Instead, if I use the code below, domain1 works but domain2 give 500 Bad Gateway
:
upstream domain1 {
server website:8301; # same container's name of docker-compose.yml
# NB: The port must be the same of PROJECT_PORT
}
upstream domain2 {
server geoserver:80; # same container's name of docker-compose.yml
}
server {
listen 80;
listen [::]:80;
server_name 127.0.0.1; # FOR STAGING ONLY
error_log /var/log/nginx/error.log warn;
access_log /var/log/nginx/access.log combined;
location / {
proxy_pass http://domain1/;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_redirect off;
# max uploadable file size
client_max_body_size 4G;
}
location /static/ {
# static folder on the server
alias /app/web/static-folder/;
}
location /media/ {
# media folder on the server
alias /app/web/media-folder/;
}
}
server {
server_name 127.0.0.2; # FOR STAGING ONLY
listen 80;
listen [::]:80;
server_tokens off;
root /usr/share/nginx/html;
index index.html;
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types
text/plain
text/css
application/json
application/javascript
application/x-javascript
text/xml application/xm
application/xml+rss
text/javascript;
underscores_in_headers on;
proxy_set_header HOST $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_buffering on;
proxy_buffer_size 1k;
proxy_buffers 24 4k;
proxy_busy_buffers_size 8k;
proxy_max_temp_file_size 2048m;
proxy_temp_file_write_size 32k;
location / {
deny all;
return 301 /geoserver;
}
location /geoserver {
proxy_pass http://domain2/geoserver/;
}
}
Why happen this?