加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 运营中心 > Nginx > 正文

代理 – 如何使用nginx将address.com/foo/bar重定向到address.co

发布时间:2020-12-13 21:23:53 所属栏目:Nginx 来源:网络整理
导读:我在我的服务器上运行nginx ansel.ms和ansel.ms:46156上的一个node.js应用程序. 我想设置nginx,所以它重定向所有的东西 ansel.ms/rhythm 至 ansel.ms:46156.ansel.ms/rhythm/sub/path 应该成为 ansel.ms:46156/sub/path 这是我的文件在网站可用: upstream r

我在我的服务器上运行nginx ansel.ms和ansel.ms:46156上的一个node.js应用程序.

我想设置nginx,所以它重定向所有的东西

ansel.ms/rhythm

ansel.ms:46156.


ansel.ms/rhythm/sub/path

应该成为

ansel.ms:46156/sub/path

这是我的文件在网站可用:

upstream rhythm {
    server ansel.ms:46156;
}

server {
    listen   80;
    server_name ansel.ms www.ansel.ms;
    access_log /srv/www/ansel.ms/logs/access.log;
    error_log /srv/www/ansel.ms/logs/error.log;

    location / {
        root   /srv/www/ansel.ms/public_html;
        index  index.html index.htm;
    }

    location ~ .php${
        include fastcgi_params;
        fastcgi_pass  127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param  SCRIPT_FILENAME  /srv/www/ansel.ms/public_html$fastcgi_script_name;
    }

    location /rhythm{
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-NginX-Proxy true;

        proxy_pass http://rhythm;
        proxy_redirect off;
    }
}

我真的不明白这是做什么(proxy_set_header的东西),我只是复制&从几个来源粘贴它.

它不工作

你能给我一个提示什么改变,所以这是我上面描述的?
谢谢!

最佳答案
我无法发现您的配置文件中的错误;我也是一个nginx-newbie.

但是这里是我的完整的nginx.conf配置文件,它将http:// myhost / cabaret / foo / bar重定向到http:// myhost:8085 / foo / bar:

user www-data;
worker_processes  1;
error_log  /var/log/nginx/error.log;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include     /etc/nginx/mime.types;
    access_log  /var/log/nginx/access.log;
    sendfile        on;
    keepalive_timeout  65;
    tcp_nodelay        on;

    server {

        listen   *:80; ## listen for ipv4
        access_log  /var/log/nginx/localhost.access.log;
        location /cabaret {
               rewrite /cabaret(.*) $1 break;
               proxy_pass http://127.0.0.1:8085;
               proxy_redirect     off;
               proxy_set_header   Host             $host;
               proxy_set_header   X-Real-IP        $remote_addr;
               proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
        }
    }
}

这不是完美的,因为它不会与http:// myhost / cabaret一起工作,只有如果在如下http:// myhost / cabaret /或http:// myhost / cabaret / foo / bar之后的一个斜杠.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读