Kohei Murakami
Kohei Murakami

Reputation: 11

How to remove port number from url, and add slug with node app?

I have deployed nodebb application on nginx, and trying to combine with my site.

My site is http://example.com. I successed to show node app on http://example.com:4567 either http://example.com(port number removed).

However, I'd like to show them with the url like http://example.com/nodebb.

I tried like the code below.

config.json

{
    "url": "http://example.com/nodebb",
    "secret": "secret",
    "database": "mongo",
    "port": 4567,
    "mongo": {
        "host": "127.0.0.1",
        "port": "27017",
        "username": "nodebb",
        "password": "pass",
        "database": "nodebb"
    }
}

nginx.conf

location / {
    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_set_header Host $http_host;
    proxy_set_header X-NginX-Proxy true;
    proxy_pass http://127.0.0.1/nodebb:4567;
    proxy_redirect off;
    # Socket.IO Support
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
}

However, it returned "not found". I have no idea how to make new slug and put node app into it. Any help is appreciated.

Upvotes: 1

Views: 395

Answers (1)

night-gold
night-gold

Reputation: 2441

You have the right answer to the problem, you just need to add more options to your proxy_pass to completely resolve your problem.

I think this post answers your question: https://serverfault.com/questions/379675/nginx-reverse-proxy-url-rewrite

Upvotes: 1

Related Questions