Score:-1

Nginx: remove port from URL

hn flag

I got a service running via npm on port 3000.

My nginx configuration looks like this:

server {
    listen 80 default_server;
    listen [::]:80 default_server;
    root /var/www/html/public/;

    # Add index.php to the list if you are using PHP
    index index.html index.htm index.nginx-debian.html;

    server_name _;
    return 301 http://fake.url:3000$request_uri;
}

Its working, i can open the site with browser. But in the URL the :3000 appears. How can i remove it from the URL?

Lex Li avatar
vn flag
Use `proxy_pass` please, https://docs.nginx.com/nginx/admin-guide/web-server/reverse-proxy/
Score:0
za flag
server {
    listen 80 default_server;
    listen [::]:80 default_server;

    location {
        proxy_pass http://fake.url:3000;
    }
}
erax avatar
hn flag
I had this one before. But now i found my mistake. I had this line " try_files $uri $uri/ =404; " After i removed it, proxy_pass http://fake.url:3000; worked just fine
drookie avatar
za flag
`try_files` in one location with `proxy_pass` drastically changes the behavior indeed.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.