skip to Main Content

I am really new to server configuration. I have a rails application locally and I have access to an amazon EC2 server instance. I am required to use nginx for web server and puma for application server. Can someone kindly explain to me in detail (file creation, directory, command etc) how I can make that application up and running for public access via the domain?

My rails app directories are:

$~ server/user/home/apps/myapp/shared/...
$~ server/user/home/apps/myapp/current/...

I have tried capistrano. But no matter which ever tutorial I follow, I always end up having .../shared/tmp/sockets/puma.myapp.sock failed (2: No such file or directory) while connecting to upstream... error.

2

Answers


  1. here are the steps that worked for me:

    Install Nginx

    1. sudo apt install nginx
    2. sudo ufw app list
    3. sudo ufw allow 'Nginx HTTP'

    Setup Server

    1. sudo nano /etc/nginx/sites-available/appname.
    2. Copy the following template into the file and replace appname with the name of your app:
    server {
        listen 80;
    
        root /home/apps/myapp/public;
        server_name appname.com www.appname.com;
        index index.htm index.html;
    
            location ~ /.well-known {
                allow all;
            }
    
            location / {
            proxy_pass http://localhost:3000;
            proxy_set_header Host $host;
            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;
        }
    }
    
    1. sudo ln -s /etc/nginx/sites-available/repuestosgonnet /etc/nginx/sites-enabled/
    2. sudo nano /etc/nginx/nginx.conf
    3. Uncomment this line: server_names_hash_bucket_size 64;
    4. Optional: Uncomment this line: server_tokens off;
    5. Test syntax: sudo nginx -t
    6. Restart Nginx: sudo systemctl restart nginx

    I hope that works for you!

    Let me know if you have any questions.

    Login or Signup to reply.
  2. You need to create 2 systemd service files so that it launches puma for you:

    appname.service:

    [Unit]
    Description=Puma HTTP Server for appname
    After=network.target
    Requires=appname.socket
    
    [Service]
    Type=simple
    Environment=RAILS_ENV=production
    WorkingDirectory=/user/home/apps/myapp/current/
    ExecStart=/user/home/apps/.rbenv/shims/puma -e production -C /user/home/apps/myapp/shared/puma.rb /user/home/apps/myapp/current/config.ru
    ExecStop=/user/home/apps/.rbenv/shims/puma -e production -C /user/home/apps/myapp/shared/puma.rb stop
    ExecReload=/user/home/apps/.rbenv/shims/puma -e production -C /user/home/apps/myapp/shared/puma.rb phased-restart
    
    PIDFile=/user/home/apps/myapp/shared/tmp/pids/puma.pid
    
    Restart=always
    RestartSec=8
    KillMode=process
    SyslogIdentifier=puma
    
    [Install]
    WantedBy=multi-user.target
    

    appname.socket:

    [Unit]
    Description=Puma HTTP Server Accept Sockets
    
    [Socket]
    ListenStream=0.0.0.0:9294
    ListenStream=0.0.0.0:9295
    
    NoDelay=true
    ReusePort=true
    Backlog=1024
    
    [Install]
    WantedBy=sockets.target
    

    Then you can relaunch systemd loader

    systemctl daemon-reload
    

    And enable the files

    systemctl enable myappli_puma_env.service myappli_puma_env.socket
    

    And finally:

    cap puma:start
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search