regex - Nginx 动态虚拟主机返回 ERR_INVALID_REDIRECT
问题描述
我正在尝试将服务器设置为使用单个 conf 文件来为所有开发站点提供服务。所以我的 /ect/nginx/site-available/dev.example.com 看起来像这样:
server {
listen 80;
server_name ~^(?<folder>[^.]*).(?<user>[^.]*).dev.example.com;
charset utf-8;
index index.php index.html index.htm;
root /var/www/projects/dev/$user/$folder/htdocs;
access_log /var/www/projects/dev/$user/$folder/access.log;
error_log /var/www/projects/dev/commons/logs/htdocs/error.log;
location ~* .(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf|js|css)$ {
access_log off;
log_not_found off;
expires 30d;
add_header Pragma "public";
}
location / {
try_files $uri $uri/ /index.php?$args;
auth_basic "Restricted Content";
auth_basic_user_file /etc/nginx/.htpasswd;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param APPLICATION_ENV $user;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
正则表达式工作正常,如果我使用带有 phpinfo() 的 index.php 运行http://energy.magana.dev.emaple.com,则文件正在工作,似乎一切正常......但如果我运行 wordpress我得到 ERR_INVALID_REDIRECT。
如果我在没有正则表达式的情况下更改文件 /ect/nginx/site-available/dev.example.com 并设置绝对路径,一切正常。
我缺少什么?
解决方案
问题是变量 SERVER_NAME 被解释为~^(?<folder>[^.]*).(?<user>[^.]*).dev.example.com
修复这个覆盖变量的工作
fastcgi_param SERVER_NAME $folder.$user.dev.example.com;
推荐阅读
- java - Java 如何在 Intellij 中找到 spark、Hadoop 和 AWS jars
- ruby - 为什么调用'is_a?方法上的对象'返回'true'?
- python - 我们如何解析 DataFrame.describe()?
- javascript - 在 Javascript 中使用 Promise 访问值
- angular - 使用 RxJS combineLatest 过滤 observables?
- reactjs - AnyChart-react 绘图在第二次渲染时消失
- java - Java 选择列表的元素
- azure - 使用 Azure ARM 模板创建 AKS 群集并部署我的 Kubernetes 应用程序
- ios - MKMarkerAnnotationView selectAnnotation() 同时显示 MarkerView 和标注
- sql - 如何为多个表创建外键?