当前位置 博文首页 > 无限迭代中......:Nginx——反向代理&路径重写&重定向

    无限迭代中......:Nginx——反向代理&路径重写&重定向

    作者:[db:作者] 时间:2021-07-19 16:22

    示例

    #http节点中可以添加多个server节点
        server{
            #听443端口
            listen 8443 ssl;
            #对应的域名,把www.shentuzhiganga.top改成你们自己的域名就可以了
            server_name zstu.shentuzhiganga.top;
            #从腾讯云获取到的第一个文件的全路径
            ssl_certificate /opt/etc/ssl/4084041_shentuzhigang.top.pem;
            #从腾讯云获取到的第二个文件的全路径
            ssl_certificate_key /opt/etc/ssl/4084041_shentuzhigang.top.key;
            ssl_session_timeout 5m;
            ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
            ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
            ssl_prefer_server_ciphers on;
            #这是我的主页访问地址,?.?为使用的是静态的html网页,所以?.?接使用location就可以完成了。
    
            location /jwglxt {
                proxy_set_header  Host  $host;
                proxy_pass http://jwglxt.zstu.edu.cn;
            }
    
            location ~ /zftal* {
                proxy_pass http://jwglxt.zstu.edu.cn;
            }
            location /ykt {
                proxy_set_header  Host  $host;
                rewrite ^/ykt/(.*)$ /$1 break;
                proxy_pass http://ykt.zstu.edu.cn;
                proxy_redirect http://ykt.zstu.edu.cn/ https://zstu.shentuzhigang.top/ykt/;
                proxy_redirect https://zstu.shentuzhigang.top/ https://zstu.shentuzhigang.top/ykt/;
                proxy_redirect http://zstu.shentuzhigang.top/ https://zstu.shentuzhigang.top/ykt/;
    
            }
            location /stu {
                proxy_set_header  Host  $host;
                rewrite ^/stui/(.*)$ /$1 break;
                proxy_pass http://stu.zstu.edu.cn;
            }
            location / {
                    #文件夹
                    root /usr/share/nginx/html;
                    #主页文件
                    index index.html;
            }
        }
    
    

    参考文章

    nginx重定向
    nginx 之 proxy_redirect详解
    nginx之location规则及地址重写

    cs