Go to /etc/nginx/conf.d
delete all files in it and create two files MyAppDevelopment.conf
and MyAppProduction.conf
(change MyApp
to your app name).
Add to MyAppDevelopment.conf
:
upstream MyAppDevelopment {
server unix:///tmp/MyAppDevelopment.sock;
}
server {
listen 54321;
server_name site.com *.site.com;
access_log /var/log/nginx/myapp-access.log;
location / {
root /home/luna/www/myapp/public;
try_files $uri @app;
gzip_static on;
expires max;
add_header Cache-Control public;
}
location @app {
proxy_pass http://MyAppDevelopment;
proxy_set_header X-Real-IP $remote_addr;
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_next_upstream error timeout invalid_header http_502;
proxy_max_temp_file_size 0;
}
}
Add to MyAppProduction.conf
:
upstream MyAppProduction {
server unix:///tmp/MyAppProduction.sock;
}
server {
listen localhost:8080;
access_log /var/log/nginx/myapp-access.log;
location / {
root /home/luna/www/myapp/public;
try_files $uri @app;
gzip_static on;
expires max;
add_header Cache-Control public;
}
location @app {
proxy_pass http://MyAppProduction;
proxy_set_header X-Real-IP $remote_addr;
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_next_upstream error timeout invalid_header http_502;
proxy_max_temp_file_size 0;
}
}
(no you can't
join similar settings)
In /etc/nginx/nginx.conf
add:
gzip on;
# Default server
server {
listen 8080 default_server;
listen 54321 default_server;
return 404;
}
include /etc/nginx/conf.d/*.conf;
Then start servers:
bundle exec puma -e development -b unix:///tmp/MyAppDevelopment.sock --debug
bundle exec puma -e production -b unix:///tmp/MyAppProduction.sock
Or in background:
bundle exec puma -e development -db unix:///tmp/MyAppDevelopment.sock
bundle exec puma -e production -db unix:///tmp/MyAppProduction.sock