nginx URLRewrite基础配置

环境准备:

主机 ip
control01 192.168.29.128
nginx01 192.168.29.101

在两台机器上分别部署nginx

control01主机nginx配置的内容如下:

复制代码
worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;

    server {
        listen       80;
        server_name  localhost;
        location / {
            rewrite ^/rw.html  /hello.html  break;
            proxy_pass http://192.168.29.101;
            root   html;
            #index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}
复制代码

nginx01主机新建个静态页面文件 /usr/local/nginx/html/hello.html

root@nginx01:~# cat /usr/local/nginx/html/hello.html 
<h1> URL rewrite success! </h1>

 

这里配置的实验目的是,访问control01的nginx 192.168.29.128/rw.html,跳转到 192.168.29.101/hello.html。没错做了个反向代理。

验证结果

 

posted @   高佳丰  阅读(113)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
点击右上角即可分享
微信分享提示