How can I configure access from external ip to internal ip on GCP through nginx reverse proxy?

对着背影说爱祢 提交于 2019-12-13 03:43:17

问题


Can't connect to application through External 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/

回答1:


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


来源:https://stackoverflow.com/questions/56094578/how-can-i-configure-access-from-external-ip-to-internal-ip-on-gcp-through-nginx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!