I'm stuck with very strange Nginx' behavior. I have 2 RoR sites, that are working with Puma.First site (app1.com) is working like should, but when i try to access app2.com, i'm just getting app1.com pages but with domain name of app2.com. The most interestin this that if in the nginx.conf i replace include /etc/nginx/sites-enabled/;* to line with direct link to site (i.e. sites-enabled/app2; sites-enabled/app1;) i can get correct response from app2, but app1 changes places with app1. What i missing?
So this is my Nginx config:
upstream puma {
server unix:///home/dev/www/apps/app1/shared/tmp/sockets/puma_app1.sock;
}
server {
listen 80;
server_name app1.com
root /home/dev/www/apps/app1/current/public;
access_log /home/dev/www/apps/app1/shared/log/nginx.access.log;
error_log /home/dev/www/apps/app1/shared/log/nginx.error.log info;
try_files $uri/index.html $uri @puma;
location @puma {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_redirect off;
proxy_pass http://puma;
# proxy_set_header X-NginX-Proxy true;
}
location /home/dev/www/apps/app1/current/public/assets/* {
#location ~* ^/assets/ {
expires 1y;
add_header Cache-Control public;
add_header Last-Modified "";
add_header ETag "";
break;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 10;
}
And for second app:
upstream puma2{
server unix:///home/dev/www/apps/app2/shared/tmp/sockets/puma_app2.sock;
}
server {
listen 80;
server_name app2.com;
root /home/dev/www/apps/app2/current/public;
access_log /home/dev/www/apps/app2/shared/log/nginx.access.log;
error_log /home/dev/www/apps/app2/shared/log/nginx.error.log info;
try_files $uri/index.html $uri @puma2;
location @puma2 {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_redirect off;
proxy_pass http://puma2;
# proxy_set_header X-NginX-Proxy true;
}
location /home/dev/www/apps/app2/current/public/assets/* {
expires 1y;
add_header Cache-Control public;
add_header Last-Modified "";
add_header ETag "";
break;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 10;
}
The nginx.conf file is:
user dev;
worker_processes auto;
error_log /var/log/nginx/error.log error;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
sendfile on;
tcp_nopush on;
# include /etc/nginx/sites-enabled/app2;
# include /etc/nginx/sites-enabled/app1;
include /etc/nginx/sites-enabled/*;
keepalive_timeout 65;
gzip on;
gzip_disable "msie6";
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml
application/xml+rss text/javascript application/javascript;
}
To give full info, i should say that all apps hosts on Digital Ocean VPS, but nameservers of app1 is on DO (but was bought on godaddy, i just transfered nameservers and then added A and CNAME records on DO account), and domain name of app2 is on godaddy so i added an A and CNAME records to make it works.
server_name
statement for app2 is correct? It must be an exact match of the domain name you use to access the website.app1
because it becomes the onlyserver
block and will respond to any domain name. See this document.