0

The are two web applications (websites) written on Go. One is turalasgar.pro (here I am using Go built-in server). Another is engossip.com (for now it displays the same ip as former). I have a vps. I know I should use Nginx, but have no idea how? I have heard of Caddy. Please, I need only nginx server, not Caddy. What I need is run two (or more) applications by using my same vps. How should I configure Nginx configuration? Whether by listening to different ports or to the same port. Practical advices and examples highly appreciated.

3 Answers 3

6

It's called reverse proxy. Each application uses it's own port to listen. And then you just point to them in nginx config:

server {
    listen 80;
    server_name turalasgar.pro;
    location / {
        proxy_pass http://localhost:8080;
        ...
    }
}

server {
    listen 80;
    server_name engossip.com;
    location / {
        proxy_pass http://localhost:8081;
        ...
    }
}
Sign up to request clarification or add additional context in comments.

5 Comments

Shall I write the same server ip to both domain? And if so then Nginx will realize which domain comes from and accordingly it will map?
And when I copy the code you have given I got this error. Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.
Both DNS must have the same IP. Requests that came to the turalasgar.pro will go to localhost:8080. Requests that came to the engossip.com will go to localhost:8081.
@tural-Əsgərov maybe you forgot to replace ... with the actual config values? You can find the docs here.
Thank you very much for your help.
1

Well is really easy.

follow this guide:

https://www.digitalocean.com/community/tutorials/how-to-use-martini-to-serve-go-applications-behind-an-nginx-server-on-ubuntu

After you achieved one application working with martini+nginx just add another server block for the other app.

In case you need more information about server blocks:

https://www.digitalocean.com/community/tutorials/how-to-set-up-nginx-server-blocks-virtual-hosts-on-ubuntu-14-04-lts

Comments

0

Above solutions I tried but didn't work for me

https://gist.github.com/soheilhy/8b94347ff8336d971ad0

server {
listen       ...;
...
location / {
    proxy_pass http://127.0.0.1:8080;
}

location /blog {
    rewrite ^/blog(.*) /$1 break;
    proxy_pass http://127.0.0.1:8181;
}

location /mail {
    rewrite ^/mail(.*) /$1 break;
    proxy_pass http://127.0.0.1:8282;
}
...

}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.