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
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;
...
}
}
5 Comments
Tural Asgarov
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?
Tural Asgarov
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.tetafro
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 Asgarov
Thank you very much for your help.
Well is really easy.
follow this guide:
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:
Comments
Above solutions I tried but didn't work for me
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;
}
...
}