首页 > 解决方案 > 如何通过 nginx 反向代理在 GCP 上配置从外部 ip 到内部 ip 的访问?

问题描述

无法通过外部 IP 连接到应用程序。

我在 GCP 的 vm 实例(CentOS 7)上启动了 gerrit 代码审查应用程序。它适用于http://localhost:8080,我无法通过外部 IP 连接到它。我也尝试创建 NGINX 反向代理,但可能我的配置错误。顺便说一句,安装 NGINX 后,启动页面显示在外部 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/

标签: nginxgoogle-cloud-platformgerrit

解决方案


  1. 在 /etc/hosts 127.0.0.1 internal.domain 中添加一行

  2. 更新代理配置 proxy_pass http://internal.domain:8080;

它适用于我


推荐阅读