如何通过Nginx反向代理在GCP上配置从外部ip到内部ip的访问? [英] How can I configure access from external ip to internal ip on GCP through nginx reverse proxy?
问题描述
无法通过外部IP连接到应用程序.
Can't connect to application through External IP.
我在GCP的vm实例(CentOS 7)上启动了Gerrit代码检查应用程序. 它可以在 http://localhost:8080 上运行,并且我无法通过外部IP连接到它.我也尝试创建NGINX反向代理,但是可能我的配置错误.顺便说一句,安装NGINX之后,启动页面显示在外部ip上.
I started gerrit code review application on GCP's vm instance(CentOS 7). It works on http://localhost:8080 and I can't connect to it through external IP. Also I tried to create NGINX reverse proxy, but probably my configuration is wrong. By the way after installing NGINX, the starter page were shown on external ip.
# nginx configuration /etc/nginx/conf.d/default.conf
server {
listen 80;
server_name localhost;
auth_basic "Welcomme to Gerrit Code Review Site!";
location / {
proxy_pass http://127.0.0.1:8080;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
}
}
gerrit.config
[httpd]
listenUrl = proxy-http://127.0.0.1:8080/
推荐答案
您将localhost用作服务器名.我认为这可能会引起冲突,因为您从外部连接到服务器.您不需要server_name,因为您将通过ip连接到服务器.我建议您在nginx配置中启用日志.它将帮助您修复错误.
You use localhost as a server_name. I think that may cause conflict, because you connect to your server externally. You don't need server_name, cause you are going connect to your server by ip. And I recommend you enable logs in your nginx config. It will help you with bug fixing.
我建议您尝试以下配置:
I recommend you try this config:
server {
listen 80;
access_log /var/log/nginx/gerrit_access.log;
error_log /var/log/nginx/gerrit_error.log;
location / {
proxy_pass http://127.0.0.1:8080;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
}
}
这篇关于如何通过Nginx反向代理在GCP上配置从外部ip到内部ip的访问?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!