日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Nginx >内容正文

Nginx

Nginx--------地址重写

發布時間:2025/4/16 Nginx 239 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Nginx--------地址重写 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

?

修改配置文件(訪問a.html重定向到b.html)

1)修改Nginx服務配置:

  • [root@proxy ~]# vim /usr/local/nginx/conf/nginx.conf
  • .. ..
  • server {
  • ? ? ? ? ? ?listen 80;
  • ? ? ? ? ? server_name localhost;
  • location / {
  • ? ? ? ? ? ?root html;
  • ? ? ? ? ? ?index index.html index.htm;
  • ? ? ? ? ? ?rewrite /a.html /b.html;????????????
  • ? ? ? ? ?}
  • ? }
  • ?
  • [root@proxy ~]# echo "BB" > /usr/local/nginx/html/b.html
  • # /usr/local/nginx/sbin/nginx -s reload # firefox http://192.168.4.5/a.html

    訪問a.html重定向到b.html(跳轉地址欄)

    1)修改Nginx服務配置:

  • [root@proxy ~]# vim /usr/local/nginx/conf/nginx.conf
  • .. ..
  • server {
  • ? ? ? ? ?listen 80;
  • ? ? ? ? ?server_name localhost;
  • location / {
  • ? ? ? ? ? ? ? ? root html;
  • ? ? ? ? ? ? ? ? index index.html index.htm;
  • ? ? ? ? ? ? ? ?rewrite /a.html /b.html redirect;????????????
  • ? ? ? ? ? ? ?}
  • ? }
  • 修改配置文件(訪問192.168.4.5的請求重定向至www.caizhan99.cn)

    1) 修改Nginx服務配置

  • [root@proxy ~]# vim /usr/local/nginx/conf/nginx.conf
  • .. ..
  • server {
  • ? ? ? ? ? ? listen 80;
  • ? ? ? ? ? ?server_name localhost;
  • ? ? ? ? ? ? rewrite ^/ http://www.caizhan99.cn/;
  • location / {
  • ? ? ? ? ? ? root html;
  • ? ? ? ? ? ?index index.html index.htm;
  • # rewrite /a.html /b.html redirect;
  • ? ? ? ? ? ? ?}
  • ? ? }
  • 修改配置文件(訪問192.168.4.5/下面子頁面,重定向至www.caizhan99.cn/下相同的頁面)

    1) 修改Nginx服務配置

  • [root@proxy ~]# vim /usr/local/nginx/conf/nginx.conf
  • ?
  • .. ..
  • server {
  • listen 80;
  • server_name localhost;
  • rewrite ^/(.*)$ http://www.caizhan99.cn/$1;
  • location / {
  • ????root html;
  • ? ? index index.html index.htm;
  • # rewrite /a.html /b.html redirect;
  • ? ? ? ?}
  • }
  • 01.[root@proxy ~]# vim /usr/local/nginx/conf/nginx.conf 02. 03... .. 04.server { 05. listen 80; 06. server_name localhost; 07.rewrite ^/(.*)$ http://www.caizhan99.cn/$1; 08.location / { 09. root html; 10. index index.html index.htm; 11.# rewrite /a.html /b.html redirect; 12.} 13.}

    修改配置文件(實現curl和火狐訪問相同鏈接返回的頁面不同)

    1) 創建網頁目錄以及對應的頁面文件:

    [root@proxy ~]# echo "I am Normal page" > /usr/local/nginx/html/test.html

    [root@proxy ~]# mkdir -p /usr/local/nginx/html/firefox/

    [root@proxy ~]# echo "firefox page" > /usr/local/nginx/html/firefox/test.html

    2) 修改Nginx服務配置

  • [root@proxy ~]# vim /usr/local/nginx/conf/nginx.conf
  • .. ..
  • server {
  • ? ? ? ? ? listen 80;
  • ? ? ? ? ? server_name localhost;
  • location / {
  • ????root html;
  • ? ? index index.html index.htm;
  • ? ? ?}
  • #這里,~符號代表正則匹配,*符號代表不區分大小寫
  • ? ? ? if ($http_user_agent ~* firefox) {????????????//識別客戶端firefox瀏覽器
  • ? ? ? rewrite ^(.*)$ /firefox/$1;
  • ? ? ?}
  • ? }
  • ~]# vim /usr/local/nginx/conf/nginx.conf 02... .. 03.server { 04. listen 80; 05. server_name localhost; 06.location / { 07. root html; 08.index index.html index.htm; 09.} 10.#這里,~符號代表正則匹配,*符號代表不區分大小寫 11.if ($http_user_agent ~* firefox) { //識別客戶端firefox瀏覽器 12.rewrite ^(.*)$ /firefox/$1; 13.} 14.}

    地址重寫格式【總結】

    rewrite 舊地址 新地址 [選項];

    last 不再讀其他rewrite

    break 不再讀其他語句,結束請求

    redirect 臨時重定向

    permament 永久重定向

    ?

    總結

    以上是生活随笔為你收集整理的Nginx--------地址重写的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。