使用Nginx部署多个Go应用程序

时间:2017-08-06 20:09:58

标签: nginx go web-deployment

这是在Go上编写的两个Web应用程序(网站)。一个是turalasgar.pro(这里我使用的是Go内置服务器)。另一个是engossip.com(现在它显示与前者相同的ip)。我有一个vps。我知道我应该使用Nginx,但不知道怎么做?我听说过凯蒂。请,我只需要nginx服务器,而不是Caddy。我需要的是使用相同的vps运行两个(或更多)应用程序。我应该如何配置Nginx配置?是通过侦听不同的端口还是同一个端口。实用的建议和例子受到高度赞赏。

3 个答案:

答案 0 :(得分:5)

它被称为反向代理。每个应用程序都使用它自己的端口来监听。然后你只需在nginx配置中指向它们:

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;
        ...
    }
}

答案 1 :(得分:0)

嗯,真的很容易。

按照本指南操作:

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

使用martini + nginx实现一个应用程序后,只需为另一个应用程序添加另一个<WebView android:layout_width="match_parent" android:layout_height="match_parent" tools:layout_editor_absoluteX="8dp" tools:layout_editor_absoluteY="8dp" android:id="@+id/webview"/> 块。

如果您需要有关服务器块的更多信息,请执行以下操作:

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

答案 2 :(得分:0)

以上解决方案我尝试过但对我不起作用

<块引用>

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;
}
...

}