Nginx returning 404 on any path except / (proxy_pass)

General Tech Bugs & Fixes 2 years ago

0 1 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 16 Aug 2022, this text provides information on Bugs & Fixes related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (1)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago

 

I am using nginx as a reverse proxy to serve my various node and react applications. Basically I set a subdomain for each application.

I can query https://demo.myapp.com/ and it gets passed to the correct underlying app but if I query https://demo.myapp.com/login I get a 404. note that I get "404 Not Found" as plain text, no html no nothing.

I find this odd because I copy pasted the config of my other apps and I can definitely callhttps://myotherapp.myapp.com/login. I have looked online but I didn't find any help on this matter (because I didn't really find a way to formulate my problem ?)

Here's my config (domain names are anonymized but it's exactly the same structure)

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

# this one works fine when I call sc.example.io/login
server {
    server_name sc.example.io;

    location / {
             proxy_pass http://127.0.0.1:5102;
    }

    listen 443 ssl; # managed by Certbot                                                                                                                                                                    
    ssl_certificate /etc/letsencrypt/live/example.io/fullchain.pem; # managed by Certbot                                                                                                                 
    ssl_certificate_key /etc/letsencrypt/live/example.io/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                                                                                                                                     
}

#this ones 404's when I call demo.example.io/login
server {
    server_name demo.example.io;

    location / {
             proxy_pass http://127.0.0.1:5110;
    }


    listen 443 ssl; # managed by Certbot                                                                                                                                                                    
    ssl_certificate /etc/letsencrypt/live/example.io/fullchain.pem; # managed by Certbot                                                                                                                 
    ssl_certificate_key /etc/letsencrypt/live/example.io/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 = sc.example.io) {
        return 301 https://$host$request_uri;
    } # managed by Certbot                                                                                                                                                                                  


       server_name sc.example.io;
       listen 80;
    return 404; # managed by Certbot                                                                                                                                                                        


}

server {
    if ($host = demo.example.io) {
        return 301 https://$host$request_uri;
    } # managed by Certbot                                                                                                                                                                                  


       server_name demo.example.io;
       listen 80;
    return 404; # managed by Certbot                                                                                                                                                                        
}

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.