假设我用的泛解析域名为 *.domain.com
现在我要判断当域名不为www.domain.com并且满足条件为([\w]{2,5}).domain.com的二级域名进行重定向,将其定向到www.domain.com/domain.php?domain=([\w]{2,5})的rewrite规则。
首先我是这样写的:
set $domain '';if( $hots ~* ([\w]{2,5}).\domain\.com ){ set $domain $1; } if( $domain !~ "www" ){ rewrite ^$domain\.domain\.com(.*)$ http://www.domain.com$1?domain=$domain last;}
于是报错为\w为不安全的匹配。
然后我又改成:
set $domain '';if( $hots ~* “([\w]{2,5}).\domain\.com" ){ set $domain $1; } if( $domain != "www" ){ rewrite ^$domain\.domain\.com(.*)$ http://www.domain.com$1?domain=$domain&query_string redirect ;}
这次不报错了,但是却无法正确跳转。
所以请教一下这段代码问题出在哪,我应该如何改写?
回复讨论(解决方案)
于是报错为\w为不安全的匹配。
改写成[0-9a-zA-z]这样试试?
另外二级域名的解析也可以加在php的入口中,可以实现更灵活的功能
改成[0-9a-zA-z] 也是一样的,因之前他提示过\w的不安全后我就改成这样的,但是同样无效,后来加了双引号以后就没问题了,只是条件好像判断成不满足了

本篇文章给大家带来了关于nginx的相关知识,其中主要介绍了nginx拦截爬虫相关的,感兴趣的朋友下面一起来看一下吧,希望对大家有帮助。

nginx php403错误的解决办法:1、修改文件权限或开启selinux;2、修改php-fpm.conf,加入需要的文件扩展名;3、修改php.ini内容为“cgi.fix_pathinfo = 0”;4、重启php-fpm即可。

跨域是开发中经常会遇到的一个场景,也是面试中经常会讨论的一个问题。掌握常见的跨域解决方案及其背后的原理,不仅可以提高我们的开发效率,还能在面试中表现的更加

实验环境前端nginx:ip192.168.6.242,对后端的wordpress网站做反向代理实现复杂均衡后端nginx:ip192.168.6.36,192.168.6.205都部署wordpress,并使用相同的数据库1、在后端的两个wordpress上配置rsync+inotify,两服务器都开启rsync服务,并且通过inotify分别向对方同步数据下面配置192.168.6.205这台服务器vim/etc/rsyncd.confuid=nginxgid=nginxport=873ho

nginx部署react刷新404的解决办法:1、修改Nginx配置为“server {listen 80;server_name https://www.xxx.com;location / {root xxx;index index.html index.htm;...}”;2、刷新路由,按当前路径去nginx加载页面即可。

nginx禁止访问php的方法:1、配置nginx,禁止解析指定目录下的指定程序;2、将“location ~^/images/.*\.(php|php5|sh|pl|py)${deny all...}”语句放置在server标签内即可。

本文给大家介绍如何通过修改Nginx源码实现基于端口号的 Nginx worker进程隔离方案。看看到底怎么修改Nginx源码,还有Nginx事件循环、Nginx 进程模型、fork资源共享相关的知识。

在使用Nginx服务器的过程中,你可能会遇到打开PHP文件时出现错误的情况。这类错误一般是由于Nginx服务器对PHP文件的解析不正确所造成的。接下来,我们将一步步地探讨如何解决这一问题。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Linux new version
SublimeText3 Linux latest version

Notepad++7.3.1
Easy-to-use and free code editor

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

Dreamweaver CS6
Visual web development tools
