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 @ 2023-02-21 21:36  高佳丰  阅读(111)  评论(0编辑  收藏  举报