Nginx   发布时间:2022-05-11  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了代理 – 如何使用nginx将address.com/foo/bar重定向到address.com:port/bar?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

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

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

@H_450_7@ansel.ms/rhythm

@H_450_7@ansel.ms:46156.


ansel.ms/rhythm/sub/path

应该成为

@H_450_7@ansel.ms:46156/sub/path

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

@H_450_7@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:

@H_450_7@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之后的一个斜杠.

大佬总结

以上是大佬教程为你收集整理的代理 – 如何使用nginx将address.com/foo/bar重定向到address.com:port/bar?全部内容,希望文章能够帮你解决代理 – 如何使用nginx将address.com/foo/bar重定向到address.com:port/bar?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: