您好!欢迎来到爱源码

爱源码

热门搜索: 抖音快手短视频下载   

关于nginx的伪静态 {源码交易}

  • 时间:2022-09-01 01:29 编辑: 来源: 阅读:281
  • 扫一扫,手机访问
摘要:关于nginx的伪静态 {源码交易}
伪静态是一种可以将文件的后缀改为任何可以做的事情的方法。如果我想把一个php文件伪静态成一个html文件,这很简单。在这里,我给你详细介绍一下nginx的伪静态配置方法。需要了解的朋友可以参考一下。 NGX中使用伪静态直接在nginx中编写规则。CONF,而且不需要像apache一样打开writing section (mod_rewrite)来执行伪静态。 Nginx只需要打开nginx.conf的配置文件,在服务器中编写需要的规则即可。 复制代码如下:server { listen 80服务器名bbs.jb51.net;索引index.html index.htm index.php;root/home/www/BBS;error _ page 404/404 . htm;#配置404错误页面位置~。*.(php|php5)?$ { # fastcgi _ pass UNIX:/tmp/PHP-CGI . sock;fastcgi _ pass 127 . 0 . 0 . 1:9000;fastcgi _ index index.php;包含fcgi.conf} #这里是伪静态位置/{rewrite(。*)/设备(d+)。html $ $1/index.php?m =内容& ampampc =指数& ampampa =列表和。ampcatid = $ 2 last} access _ log access _ log off}然后重启nginx服务器伪静态生效,维护不方便。我们可以把它写在bbs_nginx.conf这样的外部文件中,在/home/www/bbs目录下创建bbs_nginx.conf文件并编写如下代码:复制代码如下:localization/{rewrite(。*)/设备(d+)。内容& ampampc =指数& ampampa =列表和。ampcatid = $ 2 last}然后在上面的代码后面添加下面的代码:复制代码如下:include/home/www/BBS/BBS _ nginx . conf;这样就可以单独管理网站根目录下的bbs_nginx.conf伪静态规则。 说了这么多理论知识,下面举个例子:1。创建新的。htaccess文件放在。使用的是htaccess文件,比如下面的Discuz论坛目录:复制代码如下:vim/var/www/html/jb51/BBS/。htaccess 2。在里面输入规则,我在这里输入Discuz的伪静态规则(这里只添加Discuz的伪静态规则):复制代码如下:# nginxrewrite rule rewrite(。*)/archiver/((FID | TID)-[w-]+html) $ $1/archiver/index.php?最后2美元;重写^(.*)/forum-([0-9]+)-([0-9]+)。html$ $1/forumdisplay.php?fid = $ 2 & ampamppage = $ 3 last重写^(.*)/thread-([0-9]+)-([0-9]+)-([0-9]+)。html$ $1/viewthread.php?tid = $ 2 & ampampextra = page % 3D $ 4 & ampamppage = $ 3 last重写^(.*)/profile-(用户名|uid)-(。+).html$ $1/viewpro.php?$2=最后$ 3;重写^(.*)/space-(用户名|uid)-(。+).html$ $1/space.php?$2=最后$ 3;重写^(.*)/tag-(。+).html$ $1/tag.php?name = $ 2 last# end nginx重写规则保存并退出 3.修改nginx配置文件:复制代码如下:vim /etc/nginx/nginx.conf4 .介绍一下。htaccess文件到需要添加伪静态的虚拟主机的服务器{}:复制代码如下:include/var/www/html/jb51/BBS/。htaccess(备注:将路径更改为您的。htaccess文件)保存并退出。 5.重新加载nginx配置文件:复制代码代码如下:/etc/init.d/nginx重新加载童鞋。这里又是重点!Nginx经常使用重写伪静态规则:伪静态规则是我们做伪静态时一个非常重要的参数。如果能多了解一些,就能快速写出最好的伪静态代码。下面给你举几个例子,希望能帮到你。 本刊内容来源于网络和日常经验,请整理一下,以备参考。 正则表达式匹配,其中:复制代码代码如下:* ~区分大小写匹配* ~ *不区分大小写匹配*!~还有!~ *是区分大小写不匹配和不区分大小写不匹配文件和目录匹配,其中:* -f和!-f用于确定文件* -d和!-d用于确定目录是否可以存在* -e和!-e用于确定文件或目录是否可以存在* -x和!-x用于判断一个文件是否可以执行。flag标志有:* last相当于Apache中的[L]标志,表示rewrite* break终止匹配。不再匹配以下规则*重定向返回302临时重定向地址栏会显示跳转后的地址*永久返回301永久重定向地址栏会显示跳转后的地址。一些可用的全局变量是, 可用于条件判断(待完成) 复制代码如下:$ args $ content _ length $ content _ type $ document _ root $ document _ uri $ host $ http _ user _ agent $ http _ cookie $ limit _ rate $ request _ body _ file $ request _ method $ remo Te _ addr $ remote _ port $ remote _ user $ request _ filename $ request _ uri $ query _ string $ scheme $ server _ protocol $ server _ addr $ server _ name $ server _ port $ uri结合QeePHP的示例复制代码如下:if(! -d $ request _ filename){重写^/([a-z-A-Z]+)/([a-z-A-Z]+)/?(.*)$ /index.php?名称空间=用户& ampamp控制器= $ 1 & ampampaction = $ 2 & ampamp最后3美元;重写^/([a-z-A-Z]+)/?$ /index.php?名称空间=用户& ampamp控制器= $ 1 last打破;多目录转换参数复制代码如下:abc.domian.com/sort/2 = > abc.domian.com/index.php?. act = sort & amp;ampname = abc & ampampid=2if ($host ~*(。*)/.域/。{ set $ sub _ name $ 1;重写^/sort//(/d+)//?$ /index.php?分类和排序。ampcid = $ sub _ name & ampampid = $ 1 last}目录交换复制代码代码如下:/123456/xxxx -> /xxxx?id = 123456重写^/(/d+)/(.+)/ /$2?id = $ 1 last比如设置nginx将用户的ie重定向到/nginx-ie目录:if($ http _ user _ agent ~ msie){ rewrite(。*)$/nginx-IE/$ 1 break;}目录自动加“/”复制代码如下:if(-d $ request _ filename){ rewrite/(。*)([/])$ http://$ host/$ 1 $ 2/permanent;}禁止htaccess复制代码代码如下:location ~//。ht {全部否认;}禁止复制多个目录。代码如下:location ~/(cron | templates)/{ deny all;打破;}禁止以/data开头的文件。诸如此类的请求。可以禁止/data/下的多级目录中的log.txt复制代码如下:location ~/data { deny all;}没有一个单独的目录可以被禁止。log.txt可以请求复制代码如下:location/search word/cron/{ deny all;}禁止复制单个文件的代码代码如下:location ~/data/SQL/data . SQL { deny all;}设置favicon.ico和robots.txt的过期时间;这里favicon.ico是99天,robots.txt是7天,没有记录404错误日志。复制代码如下:location ~(favicon . ico){ log _ not _ found off;过期99d打破;} location ~(robots . txt){ log _ not _ found off;过期7d;打破;}设置文件的过期时间;这里是600秒,访问日志复制代码没有记录如下:location ~/html/scripts/load head _ 1 . js { access _ log off;root/opt/lampp/htdocs/web;过期600;打破;}文件防盗链,设置过期时间。这里的return 412为自己设置http状态码,默认为403,以便找出链盗请求的正确副本码。代码如下:“rewrite/http://www . jb51 . net/jb51 . gif;”防盗链“access _ log off”的图片已显示。不记录访问日志,减轻压力“过期3d”浏览器缓存位置3天~ *。+/.(jpg | JPEG | gif | png | swf | rar | zip | CSS | js)$ { valid _ referers none blocked * . JB 51 . net * . jbzjj . net localhost 1.1.1.1;if($ invalid _ referer){重写http://www.jb51.net/jb51.gif; ^/ return 412;打破;} access _ log offroot/opt/lampp/htdocs/web;过期3d;打破;}只允许固定ip访问网站,添加密码复制代码如下:root/opt/htdocs/www;允许208.97.167.194;允许222.33.1.2;允许231 . 152 . 49 . 4;否定一切;auth _ basic“C1G _ ADMIN”;auth _ basic _ user _ file htpasswd将多级目录中的文件变成一个文件,增强seo效果。按如下方式复制代码:/job-123-456-789 . html指向/job/123/456/789 . html rewrite/job-([0-9]+)-([0-9]+)-(将根目录中的文件夹指向二级目录,如/shanghaijob/指向/area/shanghai/如果将最后一个改为永久,浏览器的地址栏将显示/location/shanghai/按如下方式复制代码:rewrite/([0-9a-z])*) $/area/$1/$上面的例子有一个问题就是访问/shanghai时复制代码会不匹配:rewrite/([0-9a-z]+)job $/area/$ 1/last;重写^/([0-9a-z]+)job/(.*)$/面积/$1/$2最后;这样,/shanghai也可以访问,但是页面中的相对链接不能使用。例如,。/list_1.html真实地址是/area/Shanghai a/list_1.html,会变成/list _ 1 . html,导致无法访问。 那我就不能加自动跳转了。复制代码如下:(-d $request_filename)它有一个条件,必须是真实的目录,而我的重写不是,所以如果(-d $ request _ filename) {rewrite/(。*) ([/]) $ http:/$ host/$1 }知道原因后就好办了。让我手动跳。复制代码代码如下:rewrite/([0-9a-z]+)job $/$ 1 job/permanent;重写^/([0-9a-z]+)job/(.*)$/面积/$1/$2最后;并在文件目录不存在时重定向:复制代码如下:if(!-e $ request _ filename){ proxy _ pass http://127 . 0 . 0 . 1;}域名跳转复制代码代码如下:server { listen 80服务器名jump.c1gstudio.com;索引index.html index.htm index.php;root/opt/lampp/htdocs/www;重写http://www.jb51.net/; ^/访问_注销;}多域名迁移复制代码代码如下:server _ name www.c1gstudio.net,www.c1gstudio.com;索引index.html index.htm index.php;root/opt/lampp/htdocs;if ($host ~ "c1gstudio/。net”){重写^(.*) http://www.jb51.net$1永久;}三级域名的跳转复制代码如下:if ($ http _ host ~ * "(。*)/.i/.c1gstudio/。com $ " {重写(。*)http://www.jb51.net 1美元;打破;}域名镜像复制代码代码如下:server { listen 80服务器名mirror.c1gstudio.com;索引index.html index.htm index.php;root/opt/lampp/htdocs/www;重写^/(.*)http://www.jb51.net/$1最后;access _ log off}镜像复制一个子目录的代码代码如下:location ~/php {rewrite。+http://www . jb51 . net/last;打破;} Discuz UC Enter Home (UCHome)重写复制代码如下:重写/(空间|网络)-(。+)/.html $/$ 1.php?重写= $ 2 last重写^/(space|network)/.html $/$ 1 . PHP last;重写^/([0-9]+)$ /space.php?uid = $ 1 lastdiscuz 7重写本^(.*)/Archiver/((FID | tid)-[/w/-]+/。html)$ $1/archiver/index.php?最后2美元;重写^(.*)/forum-([0-9]+)-([0-9]+)/。html$ $1/forumdisplay.php?fid = $ 2 & ampamppage = $ 3 last重写^(.*)/thread-([0-9]+)-([0-9]+)-([0-9]+)/。html$ $1/viewthread.php?tid = $ 2 & ampampextra = page/% 3D $ 4 & amp;amppage = $ 3 last重写^(.*)/profile-(用户名|uid)-(。+)/.html$ $1/viewpro.php?$2=最后$ 3;重写^(.*)/space-(用户名|uid)-(。+)/.html$ $1/space.php?$2=最后$ 3;重写^(.*)/tag-(。+)/.html$ $1/tag.php?name = $ 2 last为bbs.jb51.net news.jb51.net discuz某段单独配置域名server _ namelocation =/{ if($ http _ host ~ news/. jb51 . net $){重写^.+http://news.jb51.net/forum-831-1.html最后;打破;}}discuz ucenter头像重写优化位置~/ucenter {location ~。*/.php?$ { # fastcgi _ pass UNIX:/tmp/PHP-CGI . sock;fastcgi _ pass 127 . 0 . 0 . 1:9000;fastcgi _ index index.php;包含fcgi.conf} location/u center/data/avatar { log _ not _ found off;access _ log off位置~ /(。*)_big/。jpg $ { error _ page 404/u center/images/noavatar _ big . gif;}位置~ /(。*)_middle/。jpg $ { error _ page 404/u center/images/noavatar _ middle . gif;}位置~ /(。*)_小/。jpg $ { error _ page 404/u center/images/noavatar _ small . gif;}过期300;打破;}}jspace rewritelocation ~。*/.php?$ { # fastcgi _ pass UNIX:/tmp/PHP-CGI . sock;fastcgi _ pass 127 . 0 . 0 . 1:9000;fastcgi _ index index.php;包含fcgi.conf}地点~ * ^/index.php/{rewrite ^/index.php/(.*) /index.php?1美元休息;fastcgi _ pass 127 . 0 . 0 . 1:9000;fastcgi _ index index.php;包含fcgi.conf}附,cms常用于替换WordPress伪静态规则:复制代码如下:location/{ index index.html index.php;if(-f $ request _ filename/index . html){重写(。*)$ 1/index . html break;} if(-f $ request _ filename/index . PHP){ rewrite(。*)$ 1/index . PHP;}如果(!-f $请求文件名){重写(。*)/index . PHP;} } PHPCMS的伪静态规则:复制代码如下:location/{# #以下是PHPCMS伪静态的重写规则(。*) show-([0-9]+)-([0-9]+) \。html $ $1/show.php?itemid = $ 2 & ampamppage = $ 3;重写^(.*)list-([0-9]+)-([0-9]+)\。html$ $1/list.php?catid = $ 2 & ampamppage = $ 3;重写^(.*)show-([0-9]+)\。html$ $1/show.php?specialid = $ 2;# # # #以下是PHPWind伪静态的重写规则:rewrite(。*)-htm-(。*)$ $ 1.php?最后2美元;重写^(.*)/simple/([a-z0-9\_]+\。html)$ $1/simple/index.php?最后2美元;}ECSHOP伪静态规则:复制代码如下:if(!-e$request _ filename){重写“^/index\.html" /index.php最后;最后重写“^/category$”/index . PHP;重写《^/feed-c([0-9]+)\.》xml$" /feed.php?cat = $ 1 last重写《^/feed-b([0-9]+)\.》xml$" /feed.php?brand = $ 1 last重写《^/feed\.》XML $ "/feed . PHP last;重写《^/category-([0-9]+)-b([0-9]+)-min([0-9]+)-max([0-9]+)-attr([^-]*)-([0-9]+)-(.》+)-([a-zA-Z]+)(。*)\.html$" /category.php?id = $ 1 & ampampbrand = $ 2 & ampampprice _ min = $ 3 & ampampprice _ max = $ 4 & ampampfilter _ attr = $ 5 & ampamppage = $ 6 & ampampsort = $ 7 & ampamp订单=最后8美元;重写《^/category-([0-9]+)-b([0-9]+)-min([0-9]+)-max([0-9]+)-attr([^-]*)(.》*)\.html$" /category.php?id = $ 1 & ampampbrand = $ 2 & ampampprice _ min = $ 3 & ampampprice _ max = $ 4 & ampampfilter _ attr = $ 5 last重写《^/category-([0-9]+)-b([0-9]+)-([0-9]+)-(.》+)-([a-zA-Z]+)(。*)\.html$" /category.php?id = $ 1 & ampampbrand = $ 2 & ampamppage = $ 3 & ampampsort = $ 4 & ampamp订单=最后5美元;重写《^/category-([0-9]+)-b([0-9]+)-([0-9]+)(.》*)\.html$" /category.php?id = $ 1 & ampampbrand = $ 2 & ampamppage = $ 3 last重写《^/category-([0-9]+)-b([0-9]+)(.》*)\.html$" /category.php?id = $ 1 & ampampbrand = $ 2 last重写《^/category-([0-9]+)(.》*)\.html$" /category.php?id = $ 1 last重写《^/goods-([0-9]+)(.》*)\.html" /goods.php?id = $ 1 last重写《^/article_cat-([0-9]+)-([0-9]+)-(.》+)-([a-zA-Z]+)(。*)\.html$" /article_cat.php?id = $ 1 & ampamppage = $ 2 & ampampsort = $ 3 & ampamp订单=最后4美元;重写《^/article_cat-([0-9]+)-([0-9]+)(.》*)\.html$" /article_cat.php?id = $ 1 & ampamppage = $ 2 last重写《^/article_cat-([0-9]+)(.》*)\.html$" /article_cat.php?id = $ 1 last重写《^/article-([0-9]+)(.》*)\.html$" /article.php?id = $ 1 last重写《^/brand-([0-9]+)-c([0-9]+)-([0-9]+)-(.》+)-([a-zA-Z]+)\。html" /brand.php?id = $ 1 & ampamp猫= $ 2 & ampamppage = $ 3 & ampampsort = $ 4 & ampamp订单=最后5美元;重写《^/brand-([0-9]+)-c([0-9]+)-([0-9]+)(.》*)\.html" /brand.php?id = $ 1 & ampamp猫= $ 2 & ampamppage = $ 3 last重写《^/brand-([0-9]+)-c([0-9]+)(.》*)\.html" /brand.php?id = $ 1 & ampampcat = $ 2 last重写《^/brand-([0-9]+)(.》*)\.html" /brand.php?id = $ 1 last重写《^/tag-(.》*)\.html" /search.php?关键字= $ 1 last重写《^/snatch-([0-9]+)\.》html$" /snatch.php?id = $ 1 last重写《^/group_buy-([0-9]+)\.》html$" /group_buy.php?查看& ampampid = $ 1 last重写《^/auction-([0-9]+)\.》html$" /auction.php?查看& ampampid = $ 1 last重写《^/exchange-id([0-9]+)(.》*)\.html$" /exchange.php?id = $ 1 & ampampact =最后查看;重写《^/exchange-([0-9]+)-min([0-9]+)-max([0-9]+)-([0-9]+)-(.》+)-([a-zA-Z]+)(。*)\.html$" /exchange.php?cat _ id = $ 1 & ampampintegral _ min = $ 2 & ampampintegral _ max = $ 3 & ampamppage = $ 4 & ampampsort = $ 5 & ampamp订单=最后6美元;重写^/exchange-([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)(。*)\.html$" /exchange.php?cat _ id = $ 1 & ampamppage = $ 2 & ampampsort = $ 3 & ampamp订单=最后4美元;重写《^/exchange-([0-9]+)-([0-9]+)(.》*)\.html$" /exchange.php?cat _ id = $ 1 & ampamppage = $ 2 last重写《^/exchange-([0-9]+)(.》*)\.html$" /exchange.php?cat _ id = $ 1 last}SHOPEX伪静态规则:复制代码如下:location/{if(!-e$请求文件名){重写^/(.+\.(html | XML | JSON | htm | PHP | JSP | ASP | shtml))$/index . PHP?最后1美元;}}SaBlog 2.0:复制代码代码如下:#仅用月份进行存档重写"/date/([0-9] {6})/?([0-9]+)?/?$" /index.php?行动=文章& ampampsetdate = $ 1 & ampamppage = $ 2 last#未分类翻页重写/page/([0-9]+)?/?$ /index.php?行动=文章& ampamppage = $ 1 last#分类重写/类别/([0-9]+)/?([0-9]+)?/?$ /index.php?行动=文章& ampampcid = $ 1 & ampamppage = $ 2 last重写^/category/([^/]+)/?([0-9]+)?/?$ /index.php?行动=文章& ampamp卷曲= $ 1 & ampamppage = $ 2 last#存档,高级搜索重写/(存档|搜索|文章|链接)/?$ /index.php?action = $ 1 last#全批评,标签列表,引用列表带分页重写/(评论|标签列表|曲目|文章)/?([0-9]+)?/?$ /index.php?action = $ 1 & ampamppage = $ 2 last#写^/tag/([^/]+)/?([0-9]+)?/?$ /index.php?行动=文章& ampampitem = $ 1 & ampamppage = $ 2 last#文章重写/存档/([0-9]+)/?([0-9]+)?/?$ /index.php?行动=表演& ampampid = $ 1 & ampamppage = $ 2 last# RSS重写^/rss/([0-9]+)?/?$ /rss.php?cid = $ 1 last重写^/rss/([^/]+)/?$ /rss.php?url = $ 1 last#让用户重写/uid/([0-9]+)/?([0-9]+)?/?$ /index.php?行动=文章& ampampuid = $ 1 & ampamppage = $ 2 last重写^/user/([^/]+)/?([0-9]+)?/?$ /index.php?行动=文章& ampampuser = $ 1 & ampamppage = $ 2 last#地图文件重写sitemap . XML sitemap.php最后;#自定义链接重写(。*)/([0-9a-za-z \-\ _]+)/?([0-9]+)?/?$ $1/index.php?行动=表演& ampamp别名= $ 2 & ampamppage = $ 3 lastUZ7伪静态规则:复制代码如下:rewrite/Archiver/((FID | TID)-[\ w \-]+\ html)$/Archiver/index . PHP?最后1美元;重写^/forum-([0-9]+)-([0-9]+)\.html$ /forumdisplay.php?fid = $ 1 & ampamppage = $ 2 last重写^/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ /viewthread.php?tid = $ 1 & ampampextra = page \ % 3D $ 3 & ampamppage = $ 2 last重写^/space-(username|uid)-(.+)\.html$ /space.php?$1=最后$ 2;重写^/tag-(.+)\.html$ /tag.php?name = $ 1 lastTypecho:复制代码如下:location/{ index index.php,index.html;if(-f $ request _ filename/index . html){重写(。*)$ 1/index . html break;} if(-f $ request _ filename/index . PHP){ rewrite(。*)$ 1/index . PHP;}如果(!-f $请求文件名){重写(。*)/index . PHP;}}示例:shopex使用伪静态复制代码如下:...……location /{if(!-e$请求文件名){重写^/(.*)$ /index.php?最后1美元;}}到目前为止,你觉得伪静态很厉害吗?如果你真的想练,那就开始练吧。


  • 全部评论(0)
资讯详情页最新发布上方横幅
最新发布的资讯信息
【域名/主机/服务器|】qq邮箱提醒在哪里打开(2024-06-04 18:58)
【技术支持|常见问题】1556原创ng8文章搜索页面不齐(2024-05-01 14:43)
【技术支持|常见问题】1502企业站群-多域名跳转-多模板切换(2024-04-09 12:19)
【技术支持|常见问题】1126完美滑屏版视频只能显示10个(2024-03-29 13:37)
【技术支持|常见问题】响应式自适应代码(2024-03-24 14:23)
【技术支持|常见问题】1126完美滑屏版百度未授权使用地图api怎么办(2024-03-15 07:21)
【技术支持|常见问题】如何集成阿里通信短信接口(2024-02-19 21:48)
【技术支持|常见问题】算命网微信支付宝产品名称年份在哪修改?风水姻缘合婚配对_公司起名占卜八字算命算财运查吉凶源码(2024-01-07 12:27)
【域名/主机/服务器|】帝国CMS安装(2023-08-20 11:31)
【技术支持|常见问题】通过HTTPs测试Mozilla DNS {免费源码}(2022-11-04 10:37)

联系我们
Q Q:375457086
Q Q:526665408
电话:0755-84666665
微信:15999668636
联系客服
企业客服1 企业客服2 联系客服
86-755-84666665
手机版
手机版
扫一扫进手机版
返回顶部