Nginx中Golang App的基本配置

前端之家收集整理的这篇文章主要介绍了Nginx中Golang App的基本配置 前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我有一台运行某些Golang应用程序的CentOS 7服务器.如您所知,每个应用程序都在自己的端口上运行,可以说:9000,9100,9200,依此类推.

现在,我已经安装了Nginx来为所有网站提供服务,我为每个站点都有一个域,并且我想在端口80中接收所有请求,然后仅基于该域就必须重定向到对应的应用程序.

到目前为止,我正在尝试使用在端口9094上运行的站点之一来实现它,但是我对Nginx没有任何经验,所以我只是想知道该怎么做,但似乎无法正常工作.在文件Nginx.conf中,我添加了以下几行:

@H_404_9@server { listen 80; server_name mydomain.com; access_log logs/mydomain.log main; location / { proxy_pass http://127.0.0.1:9094; } }

我不得不提到,我没有删除文件中默认出现的以下几行:

@H_404_9@ server { listen 80 default_server; listen [::]:80 default_server; server_name _; root /usr/share/Nginx/html; # Load configuration files for the default server block. include /etc/Nginx/default.d/*.conf; location / { } error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } }

配置可以吗?并允许我添加更多网站?谢谢
如果我对域执行ping操作,则一切正常,但是如果在浏览器中打开域,则会收到状态码502

编辑:

@H_404_9@http { log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/Nginx/access.log main; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; include /etc/Nginx/mime.types; default_type application/octet-stream; # Load modular configuration files from the /etc/Nginx/conf.d directory. # See http://Nginx.org/en/docs/ngx_core_module.html#include # for more information. include /etc/Nginx/conf.d/*.conf; server { listen 80; server_name mydomain.com; access_log logs/mydomain.log main; location / { proxy_pass http://127.0.0.1:9094; } } }
最佳答案
您的服务器配置看起来还可以,并且502 Status Code表示您没有正确配置Go服务器.具体来说,Nginx完全按照您的预期进行,将请求代理到上游,或从上游来,但是从Go服务器收到无效响应.

猜你在找的Nginx相关文章