大网数据广告活动
服务器运维问答

Point Nginx reverse proxy to virtual host on different VM

· 52CE 我爱测

I have 1 VM running Nginx to distribute incoming requests for different domains (subdomains)on the same IP to different Virtual machines. my Nginx config file for one example is very basic for now. server { listen 80; listen [::]…

问题原文

原帖链接 · user695695 · CC BY-SA 4.0

I have 1 VM running Nginx to distribute incoming requests for different domains (subdomains)on the same IP to different Virtual machines.

my Nginx config file for one example is very basic for now.

server {
  listen 80;
  listen [::]:80;

  server_name cloud.something.xyz;

  location / {
      proxy_pass http://192.168.1.77;
  }
} 

This is pointing to the correct VM but it shows the default apache page on that VM instead of the desired virtual host (cloud.something.xyz).

If I forward ports to http://192.168.1.77 directly, then the subdomains / enabled sites work as expected, so I think my Apache config is fine and the problem is on the Nginx config side.

proxy_pass http://192.168.1.77/folderloacation and similar tries just give me configuration errors and other mysterious results

What am I missing to make the proxy use the correct virtual host instead of directing to the other VMs default page?

已采纳解答

原帖链接 · Daywalker · CC BY-SA 4.0

I am more aware of the Apach Based Proxy Config, but what you are missing is the preservation of the HTTP Host Header.

In your setup, the Host Header does not get sent over to your configured Proxy.

Wou have to preserve it with the module called http://wiki.nginx.org/HttpProxyModule#proxy_set_header

The appropriate answer can be found here: https://stackoverflow.com/questions/5834025/how-to-preserve-request-url-with-nginx-proxy-pass

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2018-12-19)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。