美文网首页
nginx反向代理+路径重写 配置

nginx反向代理+路径重写 配置

作者: 雨读千年 | 来源:发表于2022-09-01 22:46 被阅读0次

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;
        # 访问方式:http://127.0.0.1/1/ng1/ --> http://127.0.0.1:82 这里和方式二主要区别在于rewrite和proxy_pass的位置。
        location ~ /ng1/ {
            proxy_pass http://127.0.0.1:81;
            rewrite "^/(.*)/ng1\/(.*)$" /$2 break;
        }
        # 访问方式:http://127.0.0.1/1/ng2/ --> http://127.0.0.1:82
        location ~ /ng2/ {
            rewrite "^/(.*)/ng2/(.*)$" /$2 break;
            proxy_pass http://127.0.0.1:82;
            
        }
        # 访问方式:http://127.0.0.1/ng3/ --> http://127.0.0.1:83
        location /ng3/ {
            rewrite ^/ng3/(.*)$ /$1 break;
            proxy_pass http://127.0.0.1:83;
        }
        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
}

相关文章

  • nginx反向代理+路径重写 配置

  • Nginx应用-Location路由反向代理及重写策略

    Nginx应用-Location路由反向代理及重写策略 一、Nginx的反向代理的路由策略 Nginx是著名的高性...

  • Nginx应用场景

    反向代理,负载均衡,动静分离 1.反向代理 修改nginx配置,并重新加载 重新加载nginx配置./nginx ...

  • 01-nginx前端方向代理

    前端反向代理 1.下载nginx 2. 配置nginx.conf反向代理

  • nginx

    nginx的配置、虚拟主机、负载均衡和反向代理一nginx的配置、虚拟主机、负载均衡和反向代理二nginx的配置、...

  • nginx配置代理

    nginx 反向代理服务器,用来代理访问路径的跳转 虚拟主机的配置 访问路径: http://dev.admin....

  • nginx反向代理

    什么是反向代理 如何实现反向代理 准备工作以及安装nginx 配置nginx nginx的初始配置文件去掉注释后的...

  • VUE webpack 反向代理重写 cookie

    webpack提供的反向代理服务器在开发阶段非常方便,几行简单的代码配置就可以使用反向代理功能,包括路径重写、co...

  • nginx 配置

    nginx 多个 root页面配置 反向代理

  • 第二课 nginx+tomcat集群

    正向代理,反向代理 配置Nginx 配置文件目录:/usr/local/nginx-1.6.1/conf/ngin...

网友评论

      本文标题:nginx反向代理+路径重写 配置

      本文链接:https://www.haomeiwen.com/subject/hnxenrtx.html