C0n*_*0nk 8 regex apache nginx
我使用Nginx作为我的Apache灌注的反向代理,作为一个安全功能,它阻止除了localhost之外的所有人访问phpmyadmin,webalizer等但是使用nginx它会让Apache认为它是localhost所以它公开显示给每个人.
<LocationMatch "^/(?i:(?:xampp|security|phpmyadmin|licenses|webalizer|server-status|server-info))">
Order deny,allow
Deny from all
Allow from ::1 127.0.0.0/8 \
fc00::/7 10.0.0.0/8 172.16.0.0/12 192.168.0.0/16 \
fe80::/10 169.254.0.0/16
ErrorDocument 403 /
</LocationMatch>
Run Code Online (Sandbox Code Playgroud)
我需要将以上规则模式匹配正则表达式转换为以下内容.
location /phpmyadmin {
proxy_pass htt://127.0.0.1:8080/phpmyadmin;
allow 127.0.0.1;
deny all;
}
Run Code Online (Sandbox Code Playgroud)
非常感谢任何熟悉Nginx正则表达式的人的帮助.
以下方法可以正常工作,但会破坏搜索引擎友好的普通网站网址,例如domain.com/forums/server-info
location ~ /(xampp|security|phpmyadmin|licenses|webalizer|server-status|server-info) {
deny all;
}
Run Code Online (Sandbox Code Playgroud)
由于apache正则表达式具有'^',我们可以将'^'强制匹配从路径的开头.
location ~ ^/(xampp|security|phpmyadmin|licenses|webalizer|server-status|server-info) {
proxy_pass http://127.0.0.1:8080$request_uri;
.... allow/deny directives come here
}
Run Code Online (Sandbox Code Playgroud)
[编辑]括号内的匹配字符串存储在$ 1中.所以你可以试试
http://127.0.0.1:8080/$1
Run Code Online (Sandbox Code Playgroud)
如果那是你想要的.但是,我的理解是你想将整个uri路径传递给apache服务器.在这种情况下,使用nginx变量$ request_uri更简单.