Nginx代理域到另一个没有更改URL的域


18

我的问题在主题中。我有一个域,它是nginx的配置:

server {
listen 80;
server_name connect3.domain.ru www.connect3.domain.ru;

access_log /var/log/nginx/connect3.domain.ru.access.log;
error_log /var/log/nginx/connect3.domain.ru.error.log;

root /home/httpd/vhosts/html;
index index.html index.htm index.php;

location ~* \.(avi|bin|bmp|css|dmg|doc|docx|dpkg|exe|flv|gif|htm|html|ico|ics|img|jpeg|jpg|js|m2a|m2v|mov|mp3|mp4|mpeg|mpg|msi|pdf|pkg|png|pps|ppt|pptx|ps|rar|rss|rtf|swf|tif|tiff|txt|wmv|xhtml|xls|xml|zip)$ {
    root /home/httpd/vhosts/html;
    access_log off;
    expires 1d;
}

location ~ /\.(git|ht|svn) {
    deny all;
}

location / {
    #rewrite ^ http://connect2.domain.ru/;
    proxy_pass http://127.0.0.1:8080/;
    proxy_redirect off;
    proxy_hide_header "Cache-Control";
    add_header Cache-Control "no-store, no-cache, must-revalidate, post-check=0, pre-check=0";
    proxy_hide_header "Pragma";
    add_header Pragma "no-cache";
    expires -1;
    add_header Last-Modified $sent_http_Expires;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}

我需要将connect3.domain.ru主机代理到connect2.domain.ru,但在浏览器的地址栏中未更改URL。我注释掉的重写行可以解决此问题,但这只是重写,因此我不能使用相同的URL。

我知道这个问题很简单,但是请帮忙。谢谢。

Answers:



7

所以我想-如果我正确理解问题,这是解决方案:

 # backend.wants.this.server.com
 # browser.shows.this.server.com

server {
  listen 80;
  server_name browser.shows.this.server.com;

  location / {
     proxy_set_header Host backend.wants.this.server.com;
     proxy_redirect http://backend.wants.this.server.com/ http://browser.shows.this.server.com/; 
  }
}

这有效吗?还是即使您执行proxy_redirect,您是否也需要proxy_pass指令?
文森特·德·斯梅特

6

关于端口8080的心灵感应已关闭,因为您没有向我们显示完整的配置。

server {
    listen 80;
    server_name connect3.domain.ru www.connect3.domain.ru;

    location / {
        proxy_pass http://connect2.domain.ru;
        proxy_set_header Host connect2.domain.ru;
    }
}
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.