最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

nginx rewrite 偽靜態(tài)配置參數(shù)詳細(xì)說(shuō)明

 更新時(shí)間:2010年05月16日 21:42:04   作者:  
nginx rewrite 偽靜態(tài)配置參數(shù)和使用例子 附正則使用說(shuō)明

正則表達(dá)式匹配,其中:

  1. * ~ 為區(qū)分大小寫匹配
  2. * ~* 為不區(qū)分大小寫匹配
  3. * !~和!~*分別為區(qū)分大小寫不匹配及不區(qū)分大小寫不匹配

文件及目錄匹配,其中:

  1. * -f和!-f用來(lái)判斷是否存在文件
  2. * -d和!-d用來(lái)判斷是否存在目錄
  3. * -e和!-e用來(lái)判斷是否存在文件或目錄
  4. * -x和!-x用來(lái)判斷文件是否可執(zhí)行

flag標(biāo)記有:

  1. * last 相當(dāng)于Apache里的[L]標(biāo)記,表示完成rewrite
  2. * break 終止匹配, 不再匹配后面的規(guī)則
  3. * redirect 返回302臨時(shí)重定向 地址欄會(huì)顯示跳轉(zhuǎn)后的地址
  4. * permanent 返回301永久重定向 地址欄會(huì)顯示跳轉(zhuǎn)后的地址

一些可用的全局變量有,可以用做條件判斷(待補(bǔ)全)

  1. $args
  2. $content_length
  3. $content_type
  4. $document_root
  5. $document_uri
  6. $host
  7. $http_user_agent
  8. $http_cookie
  9. $limit_rate
  10. $request_body_file
  11. $request_method
  12. $remote_addr
  13. $remote_port
  14. $remote_user
  15. $request_filename
  16. $request_uri
  17. $query_string
  18. $scheme
  19. $server_protocol
  20. $server_addr
  21. $server_name
  22. $server_port
  23. $uri

結(jié)合QeePHP的例子

  1. if (!-d $request_filename) {
  2. rewrite ^/([a-z-A-Z]+)/([a-z-A-Z]+)/?(.*)$ /index.php?namespace=user&controller=$1&action=$2&$3 last;
  3. rewrite ^/([a-z-A-Z]+)/?$ /index.php?namespace=user&controller=$1 last;
  4. break;

多目錄轉(zhuǎn)成參數(shù)
abc.domian.com/sort/2 => abc.domian.com/index.php?act=sort&name=abc&id=2

  1. if ($host ~* (.*)\.domain\.com) {
  2. set $sub_name $1;
  3. rewrite ^/sort\/(\d+)\/?$ /index.php?act=sort&cid=$sub_name&id=$1 last;
  4. }

目錄對(duì)換
/123456/xxxx -> /xxxx?id=123456

  1. rewrite ^/(\d+)/(.+)/ /$2?id=$1 last;

例如下面設(shè)定nginx在用戶使用ie的使用重定向到/nginx-ie目錄下:

  1. if ($http_user_agent ~ MSIE) {
  2. rewrite ^(.*)$ /nginx-ie/$1 break;
  3. }

目錄自動(dòng)加“/”

  1. if (-d $request_filename){
  2. rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent;
  3. }

禁止htaccess

  1. location ~/\.ht {
  2. deny all;
  3. }

禁止多個(gè)目錄

  1. location ~ ^/(cron|templates)/ {
  2. deny all;
  3. break;
  4. }

禁止以/data開頭的文件
可以禁止/data/下多級(jí)目錄下.log.txt等請(qǐng)求;

  1. location ~ ^/data {
  2. deny all;
  3. }

禁止單個(gè)目錄
不能禁止.log.txt能請(qǐng)求

  1. location /searchword/cron/ {
  2. deny all;
  3. }

禁止單個(gè)文件

  1. location ~ /data/sql/data.sql {
  2. deny all;
  3. }

給favicon.ico和robots.txt設(shè)置過(guò)期時(shí)間;
這里為favicon.ico為99天,robots.txt為7天并不記錄404錯(cuò)誤日志

  1. location ~(favicon.ico) {
  2. log_not_found off;
  3. expires 99d;
  4. break;
  5. }
  6. location ~(robots.txt) {
  7. log_not_found off;
  8. expires 7d;
  9. break;
  10. }

設(shè)定某個(gè)文件的過(guò)期時(shí)間;這里為600秒,并不記錄訪問(wèn)日志

  1. location ^~ /html/scripts/loadhead_1.js {
  2. access_log off;
  3. root /opt/lampp/htdocs/web;
  4. expires 600;
  5. break;
  6. }

文件反盜鏈并設(shè)置過(guò)期時(shí)間
這里的return 412 為自定義的http狀態(tài)碼,默認(rèn)為403,方便找出正確的盜鏈的請(qǐng)求
“rewrite ^/ http://leech.c1gstudio.com/leech.gif;”顯示一張防盜鏈圖片
“access_log off;”不記錄訪問(wèn)日志,減輕壓力
“expires 3d”所有文件3天的瀏覽器緩存

  1. location ~* ^.+\.(jpg|jpeg|gif|png|swf|rar|zip|css|js)$ {
  2. valid_referers none blocked *.c1gstudio.com *.c1gstudio.net localhost 208.97.167.194;
  3. if ($invalid_referer) {
  4. rewrite ^/ http://leech.c1gstudio.com/leech.gif;
  5. return 412;
  6. break;
  7. }
  8. access_log off;
  9. root /opt/lampp/htdocs/web;
  10. expires 3d;
  11. break;
  12. }

只充許固定ip訪問(wèn)網(wǎng)站,并加上密碼

  1. root /opt/htdocs/www;
  2. allow 208.97.167.194;
  3. allow 222.33.1.2;
  4. allow 231.152.49.4;
  5. deny all;
  6. auth_basic "C1G_ADMIN";
  7. auth_basic_user_file htpasswd;

將多級(jí)目錄下的文件轉(zhuǎn)成一個(gè)文件,增強(qiáng)seo效果
/job-123-456-789.html 指向/job/123/456/789.html

  1. rewrite ^/job-([0-9]+)-([0-9]+)-([0-9]+)\.html$ /job/$1/$2/jobshow_$3.html last;

將根目錄下某個(gè)文件夾指向2級(jí)目錄
如/shanghaijob/ 指向 /area/shanghai/
如果你將last改成permanent,那么瀏覽器地址欄顯是/location/shanghai/

  1. rewrite ^/([0-9a-z]+)job/(.*)$ /area/$1/$2 last;

上面例子有個(gè)問(wèn)題是訪問(wèn)/shanghai 時(shí)將不會(huì)匹配

  1. rewrite ^/([0-9a-z]+)job$ /area/$1/ last;
  2. rewrite ^/([0-9a-z]+)job/(.*)$ /area/$1/$2 last;

這樣/shanghai 也可以訪問(wèn)了,但頁(yè)面中的相對(duì)鏈接無(wú)法使用,
如./list_1.html真實(shí)地址是/area/shanghia/list_1.html會(huì)變成/list_1.html,導(dǎo)至無(wú)法訪問(wèn)。

那我加上自動(dòng)跳轉(zhuǎn)也是不行咯
(-d $request_filename)它有個(gè)條件是必需為真實(shí)目錄,而我的rewrite不是的,所以沒有效果

  1. if (-d $request_filename){
  2. rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent;
  3. }

知道原因后就好辦了,讓我手動(dòng)跳轉(zhuǎn)吧

  1. rewrite ^/([0-9a-z]+)job$ /$1job/ permanent;
  2. rewrite ^/([0-9a-z]+)job/(.*)$ /area/$1/$2 last;

文件和目錄不存在的時(shí)候重定向:

  1. if (!-e $request_filename) {
  2. proxy_pass http://127.0.0.1;
  3. }

域名跳轉(zhuǎn)

  1. server
  2. {
  3. listen 80;
  4. server_name jump.c1gstudio.com;
  5. index index.html index.htm index.php;
  6. root /opt/lampp/htdocs/www;
  7. rewrite ^/ http://www.c1gstudio.com/;
  8. access_log off;
  9. }

多域名轉(zhuǎn)向

  1. server_name www.c1gstudio.com www.c1gstudio.net;
  2. index index.html index.htm index.php;
  3. root /opt/lampp/htdocs;
  4. if ($host ~ "c1gstudio\.net") {
  5. rewrite ^(.*) http://www.c1gstudio.com$1 permanent;
  6. }

三級(jí)域名跳轉(zhuǎn)

  1. if ($http_host ~* "^(.*)\.i\.c1gstudio\.com$") {
  2. rewrite ^(.*) http://top.yingjiesheng.com$1;
  3. break;
  4. }

域名鏡向

  1. server
  2. {
  3. listen 80;
  4. server_name mirror.c1gstudio.com;
  5. index index.html index.htm index.php;
  6. root /opt/lampp/htdocs/www;
  7. rewrite ^/(.*) http://www.c1gstudio.com/$1 last;
  8. access_log off;
  9. }

某個(gè)子目錄作鏡向

  1. location ^~ /zhaopinhui {
  2. rewrite ^.+ http://zph.c1gstudio.com/ last;
  3. break;
  4. }

discuz ucenter home (uchome) rewrite

  1. rewrite ^/(space|network)-(.+)\.html$ /$1.php?rewrite=$2 last;
  2. rewrite ^/(space|network)\.html$ /$1.php last;
  3. rewrite ^/([0-9]+)$ /space.php?uid=$1 last;

discuz 7 rewrite

  1. rewrite ^(.*)/archiver/((fid|tid)-[\w\-]+\.html)$ $1/archiver/index.php?$2 last;
  2. rewrite ^(.*)/forum-([0-9]+)-([0-9]+)\.html$ $1/forumdisplay.php?fid=$2&page=$3 last;
  3. rewrite ^(.*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ $1/viewthread.php?tid=$2&extra=page\%3D$4&page=$3 last;
  4. rewrite ^(.*)/profile-(username|uid)-(.+)\.html$ $1/viewpro.php?$2=$3 last;
  5. rewrite ^(.*)/space-(username|uid)-(.+)\.html$ $1/space.php?$2=$3 last;
  6. rewrite ^(.*)/tag-(.+)\.html$ $1/tag.php?name=$2 last;

給discuz某版塊單獨(dú)配置域名

  1. server_name bbs.c1gstudio.com news.c1gstudio.com;
  2. location = / {
  3. if ($http_host ~ news\.c1gstudio.com$) {
  4. rewrite ^.+ http://news.c1gstudio.com/forum-831-1.html last;
  5. break;
  6. }
  7. }

discuz ucenter 頭像 rewrite 優(yōu)化

  1. location ^~ /ucenter {
  2. location ~ .*\.php?$
  3. {
  4. #fastcgi_pass unix:/tmp/php-cgi.sock;
  5. fastcgi_pass 127.0.0.1:9000;
  6. fastcgi_index index.php;
  7. include fcgi.conf;
  8. }
  9. location /ucenter/data/avatar {
  10. log_not_found off;
  11. access_log off;
  12. location ~ /(.*)_big\.jpg$ {
  13. error_page 404 /ucenter/images/noavatar_big.gif;
  14. }
  15. location ~ /(.*)_middle\.jpg$ {
  16. error_page 404 /ucenter/images/noavatar_middle.gif;
  17. }
  18. location ~ /(.*)_small\.jpg$ {
  19. error_page 404 /ucenter/images/noavatar_small.gif;
  20. }
  21. expires 300;
  22. break;
  23. }
  24. }

jspace rewrite

  1. location ~ .*\.php?$
  2. {
  3. #fastcgi_pass unix:/tmp/php-cgi.sock;
  4. fastcgi_pass 127.0.0.1:9000;
  5. fastcgi_index index.php;
  6. include fcgi.conf;
  7. }
  8. location ~* ^/index.php/
  9. {
  10. rewrite ^/index.php/(.*) /index.php?$1 break;
  11. fastcgi_pass 127.0.0.1:9000;
  12. fastcgi_index index.php;
  13. include fcgi.conf;
  14. }

相關(guān)文章

  • Nginx開啟一個(gè)參數(shù)就能讓你的WEB性能提升3倍的方法

    Nginx開啟一個(gè)參數(shù)就能讓你的WEB性能提升3倍的方法

    這篇文章主要介紹了Nginx開啟一個(gè)參數(shù)就能讓你的WEB性能提升3倍的方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2019-03-03
  • Ubuntu上安裝Nginx服務(wù)器程序及簡(jiǎn)單的環(huán)境配置小結(jié)

    Ubuntu上安裝Nginx服務(wù)器程序及簡(jiǎn)單的環(huán)境配置小結(jié)

    Nginx是一款高性能的異步非阻塞服務(wù)器應(yīng)用程序,人氣相當(dāng)高,這里我們就來(lái)看一下在Ubuntu上安裝Nginx服務(wù)器程序及簡(jiǎn)單的環(huán)境配置小結(jié):
    2016-07-07
  • nginx實(shí)現(xiàn)重寫功能和防盜鏈功能

    nginx實(shí)現(xiàn)重寫功能和防盜鏈功能

    這篇文章主要介紹了nginx實(shí)現(xiàn)重寫功能和防盜鏈功能,Nginx服務(wù)器利用 ngx_http_rewrite_module 模塊解析和處理rewrite請(qǐng)求,防盜鏈基于客戶端攜帶的referer實(shí)現(xiàn),文中通過(guò)代碼示例講解的非常詳細(xì),需要的朋友可以參考下
    2024-06-06
  • Nginx實(shí)現(xiàn)TCP和UDP代理的方法步驟

    Nginx實(shí)現(xiàn)TCP和UDP代理的方法步驟

    Nginx 1.9.13 及以上版本支持TCP/UDP代理功能,通過(guò)配置監(jiān)聽端口、后端服務(wù)器地址等參數(shù),實(shí)現(xiàn)客戶端請(qǐng)求的轉(zhuǎn)發(fā)和響應(yīng)的返回,下面就來(lái)介紹一下如何實(shí)現(xiàn),感興趣的可以了解一下
    2024-12-12
  • Nginx1.8.0版本平滑升級(jí)新版本1.9.7

    Nginx1.8.0版本平滑升級(jí)新版本1.9.7

    這篇文章主要介紹了Nginx1.8.0版本平滑升級(jí)新版本1.9.7的相關(guān)資料,需要的朋友可以參考下
    2016-02-02
  • Nginx安裝nginx-rtmp-module模塊的實(shí)現(xiàn)

    Nginx安裝nginx-rtmp-module模塊的實(shí)現(xiàn)

    nginx-rtmp-module是一個(gè)用于Nginx的第三方模塊,它使Nginx能夠支持實(shí)時(shí)多媒體流的傳輸和處理,本文主要介紹了Nginx安裝nginx-rtmp-module模塊,具有一定的參考價(jià)值,感興趣的可以了解一下
    2025-02-02
  • nginx配置SSL證書實(shí)現(xiàn)https服務(wù)的方法

    nginx配置SSL證書實(shí)現(xiàn)https服務(wù)的方法

    這篇文章主要介紹了nginx配置SSL證書實(shí)現(xiàn)https服務(wù)的方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2019-05-05
  • Nginx報(bào):Nginx?-?504?Gateway?Time-out問(wèn)題解決辦法

    Nginx報(bào):Nginx?-?504?Gateway?Time-out問(wèn)題解決辦法

    這篇文章主要給大家介紹了關(guān)于Nginx報(bào):Nginx?-?504?Gateway?Time-out問(wèn)題的解決辦法,一般是由于程序執(zhí)行時(shí)間過(guò)長(zhǎng)導(dǎo)致響應(yīng)超時(shí),例如程序需要執(zhí)行90秒,而nginx最大響應(yīng)等待時(shí)間為30秒,這樣就會(huì)出現(xiàn)超時(shí),需要的朋友可以參考下
    2024-01-01
  • nginx配置中$http_host、$host、$host:$proxy_port和$host:$server_port區(qū)別解析

    nginx配置中$http_host、$host、$host:$proxy_port和$host:$server_por

    nginx為了實(shí)現(xiàn)反向代理的需求而增加了一個(gè)ngx_http_proxy_module模塊,其中proxy_set_header指令就是該模塊需要讀取的配置文件,這篇文章主要介紹了nginx配置中$http_host、$host、$host:$proxy_port和$host:$server_port區(qū)別,需要的朋友可以參考下
    2024-03-03
  • Nginx優(yōu)化服務(wù)之網(wǎng)頁(yè)壓縮的實(shí)現(xiàn)方法

    Nginx優(yōu)化服務(wù)之網(wǎng)頁(yè)壓縮的實(shí)現(xiàn)方法

    這篇文章主要介紹了Nginx優(yōu)化服務(wù)之網(wǎng)頁(yè)壓縮的實(shí)現(xiàn)方法,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-01-01

最新評(píng)論

高陵县| 奉新县| 广南县| 观塘区| 临颍县| 故城县| 甘谷县| 鄂尔多斯市| 信阳市| 八宿县| 凉山| 华坪县| 沂源县| 无锡市| 泌阳县| 肃宁县| 山西省| 玉环县| 镇雄县| 页游| 临江市| 德昌县| 榆林市| 商洛市| 唐山市| 石景山区| 苏州市| 常州市| 长春市| 泗阳县| 揭东县| 康平县| 潜江市| 阜新| 云霄县| 乐安县| 大连市| 酒泉市| 山阳县| 蓬莱市| 江山市|