Search code examples
nginxreverse-proxynginx-reverse-proxy

I'm facing issues trying to configure reverse proxy in Nginx, for an app running in localhost


I've got Pterodactyl set up on a Digital Ocean droplet running Ubuntu v18.04.4 LTS. About a year ago I set it up along with Nginx, set up A records (panel.example.com), and it works splendidly with a Let's Encrypt SSL certificate.

A couple days ago I decided to set up The Lounge, a self hosted Web IRC client. By default it runs on port 9000. I followed their recommended instructions, changing a few things recommended by the people on their help IRC channel. Unlike the Pterodactyl panel, I want this to show up on my personal domain. So, I set up my A record to point to my DO droplet, with a host value of irc, so it would show up at irc.yash.gg. Then I used acme.sh to generate Let's Encrypt keys in standalone mode. Then, I added the config below to /etc/nginx/sites-available/thelounge.conf, symlinked that to /etc/nginx/sites-enabled/thelounge.conf. But for some reason, with the config below, it started redirecting to the "you've set up nginx correctly" page instead. And now, a couple days later, I get directed to my Pterodactyl panel at panel.sneakycraft.com instead.

I am completely lost, and I don't understand what is going on. I would really appreciate some help with this. Please let me know, if I can provide anything else to help diagnose this issue.

Thanks!

server {
    listen 80;
    listen [::]:80;
    return 301 https://$server_name$request_uri;
}

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name irc.yash.gg;

    ssl_stapling on;
    ssl_stapling_verify on;
    resolver 1.1.1.1 1.0.0.1 [2606:4700:4700::1111] [2606:4700:4700::1001] valid=300s;
    resolver_timeout 5s;

    charset utf-8;

    location ^~ /irc/ {
    proxy_pass https://127.0.0.1:9000/;
    proxy_ssl_protocols TLSv1.2 TLSv1.3;
    proxy_set_header Connection "upgrade";
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_set_header X-Forwarded-Proto $scheme;

    # by default nginx times out connections in one minute
    proxy_read_timeout 1d;
#    proxy_redirect      http://127.0.0.1:9000 https://irc.yash.gg;
}

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    access_log /var/log/nginx/thelounge.app-access.log;
    error_log  /var/log/nginx/thelounge.app-error.log error;

    # allow larger file uploads and longer script runtimes
    client_max_body_size 100m;
    client_body_timeout 120s;

    sendfile off;

    # SSL Configuration
    ssl_certificate /etc/letsencrypt/live/irc.yash.gg/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/irc.yash.gg/privkey.pem;
    ssl_session_cache shared:SSL:10m;
    ssl_trusted_certificate /etc/letsencrypt/live/irc.yash.gg/fullchain.pem;

    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_ciphers 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256';
    ssl_prefer_server_ciphers on;

    ssl_dhparam /etc/ssl/certs/dhparam.pem;
    ssl_ecdh_curve secp384r1; # Requires nginx >= 1.1.0

    # See https://hstspreload.org/ before uncommenting the line below.
    # add_header Strict-Transport-Security "max-age=15768000; preload;";
    add_header X-Content-Type-Options nosniff;
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Robots-Tag none;
    add_header Content-Security-Policy "frame-ancestors 'self'";
    add_header X-Frame-Options DENY;
    add_header Referrer-Policy same-origin;

#    location ~ \.php$ {
#        fastcgi_split_path_info ^(.+\.php)(/.+)$;
#        fastcgi_pass unix:/run/php/php7.2-fpm.sock;
#        fastcgi_index index.php;
#        include fastcgi_params;
#        fastcgi_param PHP_VALUE "upload_max_filesize = 100M \n post_max_size=100M";
#        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#        fastcgi_param HTTP_PROXY "";
#        fastcgi_intercept_errors off;
#        fastcgi_buffer_size 16k;
#        fastcgi_buffers 4 16k;
#        fastcgi_connect_timeout 300;
#        fastcgi_send_timeout 300;
#        fastcgi_read_timeout 300;
#    }

    location ~ /\.ht {
        deny all;
    }
}

Solution

  • The Lounge binds to my public IP. changed config to point to serverip:port instead of localhost and that worked.