sebastiandetering.com is my ruby on rails app.
I followed this guide to deploy my app with the mina gem rails-deployment-mina-guide_ralfebert.com.
I have https configured and it’s been working since 2022.
Now I’m trying to run another rails app for my brother on the same server using http://juliandetering.com. (https later)
http://juliandetering.com shows the same app as https://sebastiandetering.com, even though my upstream in nginx points to julsapp-live
.
/etc/nginx/sites-enabled/julsapp-live
upstream julsapp-live {
server unix:/home/julsapp-live/app/shared/unicorn.sock fail_timeout=0;
}
server {
server_name juliandetering.com;
root /home/julsapp-live/app/current/public;
location /assets/ {
gzip_static on; # serve pre-gzipped version
expires 1M;
add_header Cache-Control public;
}
location / {
try_files $uri @app;
}
location @app {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://julsapp-live;
}
listen 80;
}
server {
listen 80;
server_name www.juliandetering.com;
return 301 http://juliandetering.com$request_uri;
}
/etc/nginx/sites-enabled/rails-demo
upstream rails-demo {
server unix:/home/rails-demo/app/shared/unicorn.sock fail_timeout=0;
}
server {
server_name www.sebastiandetering.com;
root /home/rails-demo/app/current/public;
location /assets/ {
gzip_static on; # serve pre-gzipped version
expires 1M;
add_header Cache-Control public;
}
location / {
try_files $uri @app;
}
location @app {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://rails-demo;
}
listen 443 ssl; # managed by Certbot
listen [::]:443 ssl; # added by SebD 10/13/2022 to try to match peertube server conf
ssl_certificate /etc/letsencrypt/live/sebastiandetering.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/sebastiandetering.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
listen 80;
server_name www.sebastiandetering.com;
return 301 http://sebastiandetering.com$request_uri;
}
Both apps are working, here’s the systemctl status for both apps.
root@vultr:~# systemctl status rails-demo
● rails-demo.service - rails-demo service
Loaded: loaded (/etc/systemd/system/rails-demo.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2024-01-18 21:28:36 UTC; 3h 35min ago
root@vultr:~# systemctl status julsapp-live
● julsapp-live.service - julsapp-live service
Loaded: loaded (/etc/systemd/system/julsapp-live.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2024-01-18 22:46:31 UTC; 2h 17min ago
I tested changing the root and proxy_pass of rails-demo
in nginx to point to the julsapp-live
upstream, and I saw the julsapp-live
working as expected! Except now going to sebastiandetering.com would show julsapp-live
.
How do I configure nginx such that julsapp-live
is served when I go to juliandetering.com, and rails-demo
when I go to sebastiandetering.com?
Have you reload your nginx config to make the config works?
use
nginx -T | grep 'server_name '
to check which server_name nginx servered.Day after testing: now it’s working??? Somehow overnight the sites are properly served. I do not know how to explain this since I didn’t change anything. I did run
systemctl reload nginx
every time I made a change yesterday.