Report this

What is the reason for this report?

using shiny-server with nginx

Posted on August 13, 2025

In step 3, configuring server block: is your_server_ip an actual IP address, domain name, or localhost? I have the following, but have tried ip address and local host. get 504 error code:

        root /var/www/data-dancer.com;
        index index.html;

        server_name data-dancer.com www.data-dancer.com;

        location / {
             proxy_pass http://data-dancer.com:3838;
             proxy_redirect http://data-dancer.com:3838 https://$host;
             proxy_http_version 1.1;
             proxy_set_header Upgrade $http_upgrade;
             proxy_set_header Connection $connection_upgrade;
             proxy_read_timeout 20d;
        }


    listen 443 ssl; # managed by Certbot
    listen [::]:443 ssl ipv6only=on; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/data-dancer.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/data-dancer.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 {
    if ($host = www.data-dancer.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    if ($host = data-dancer.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


        listen 80;
        listen [::]:80;

        server_name data-dancer.com www.data-dancer.com;
    return 404; # managed by Certbot
}


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Heya,

The issue is in your proxy_pass configuration. You’re using data-dancer.com:3838, but Shiny Server runs locally on your server, so you should be proxying to localhost or 127.0.0.1, not your domain name.

Here’s the corrected configuration:

server {
    root /var/www/data-dancer.com;
    index index.html;
    server_name data-dancer.com www.data-dancer.com;

    location / {
        proxy_pass http://127.0.0.1:3838;
        proxy_redirect http://127.0.0.1:3838/ $scheme://$host/;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
        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;
        proxy_read_timeout 20d;
        proxy_buffering off;
    }

    listen 443 ssl; # managed by Certbot
    listen [::]:443 ssl ipv6only=on; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/data-dancer.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/data-dancer.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 {
    if ($host = www.data-dancer.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

    if ($host = data-dancer.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

    listen 80;
    listen [::]:80;
    server_name data-dancer.com www.data-dancer.com;
    return 404; # managed by Certbot
}

Key Changes Made:

  1. Changed proxy_pass: From http://data-dancer.com:3838 to http://127.0.0.1:3838
  2. Fixed proxy_redirect: Updated to properly handle redirects
  3. Added essential headers: Including Host, X-Real-IP, X-Forwarded-For, and X-Forwarded-Proto
  4. Added proxy_buffering off: Better for Shiny apps with real-time updates

Also make sure you have the connection upgrade map defined:

Add this to your main nginx configuration (usually in /etc/nginx/nginx.conf) in the http block:

http {
    # ... other configuration ...
    
    map $http_upgrade $connection_upgrade {
        default upgrade;
        '' close;
    }
    
    # ... rest of configuration ...
}

Before testing, make sure Shiny Server is actually running:

# Check if Shiny Server is running
sudo systemctl status shiny-server

# If not running, start it
sudo systemctl start shiny-server

# Test locally
curl http://localhost:3838

The 504 Gateway Timeout error was occurring because nginx was trying to connect to your domain name instead of the local Shiny Server process. By changing it to 127.0.0.1:3838, nginx will properly proxy requests to the locally running Shiny Server.

Oh and restart your Nginx server as well after the changes

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.