I have two domain a single gcp instance.
I want to run both domain different server block. Create nginx conf with two different server block but is not working properly It behave like load balancer.
Site run with nodeJS
When hit example1.com multiple time (5-6time) get example1.com and example2.com same as example2.com.
It like:
When Go example1.com
- example1.com -> example1.com
- example1.com -> example1.com
- example1.com -> example2.com
- example1.com -> example1.com
- example1.com -> example2.com
When Go example2.com
- example2.com -> example1.com
- example2.com -> example2.com
- example2.com -> example1.com
- example2.com -> example2.com
- example2.com -> example2.com
Below My Config file.
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
error_log /var/log/nginx/error.log;
proxy_cache_path /var/lib/nginx/cache keys_zone=next_static:150m;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 720s;
types_hash_max_size 4096;
client_max_body_size 20m;
client_body_timeout 320s;
sendfile_max_chunk 15m;
send_timeout 420s;
include /etc/nginx/mime.types;
default_type application/octet-stream;
include /etc/nginx/conf.d/*.conf;
upstream example2_app {
keepalive_timeout 180s;
server 0.0.0.0:4500;
}
upstream example1_app {
keepalive_timeout 180s;
server 0.0.0.0:8000;
server 0.0.0.0:8001;
}
server {
listen 80;
listen [::]:80;
server_name example1.com *example1.com;
access_log /var/log/nginx/example1/access.log main;
gzip on;
gzip_proxied any;
gzip_comp_level 4;
gzip_types text/css application/javascript text/js application/x-javascript application/xml image/png image/x-icon image/gif image/jpeg image/svg+xml application/xml+rss text/javascript application/atom+xml application/json application/x-font-ttf font/opentype;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
location / {
error_log /var/log/nginx/example1/error.log error;
proxy_next_upstream_tries 2;
proxy_http_version 1.1;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_read_timeout 320s;
proxy_connect_timeout 75s;
proxy_send_timeout 320s;
proxy_set_header Connection "";
proxy_buffering off;
proxy_pass http://example1_app;
}
}
server {
listen 80;
listen [::]:80;
server_name example2.com *.example2.com;
access_log /var/log/nginx/example2_app/access.log main;
gzip on;
gzip_proxied any;
gzip_comp_level 4;
gzip_types text/css application/javascript text/js application/x-javascript application/xml image/png image/x-icon image/gif image/jpeg image/svg+xml application/xml+rss text/javascript application/atom+xml application/json application/x-font-ttf font/opentype;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
location / {
error_log /var/log/nginx/example2/error.log error;
proxy_next_upstream_tries 2;
proxy_http_version 1.1;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_read_timeout 320s;
proxy_connect_timeout 75s;
proxy_send_timeout 320s;
proxy_set_header Connection "";
proxy_buffering off;
proxy_pass http://example2_app;
}
}
}