Php 根据服务器名称指令,为fastcgi屏蔽/重写服务器名称
我有一个PHP网站,为每个用户使用子域 我希望能够在内部将Php 根据服务器名称指令,为fastcgi屏蔽/重写服务器名称,php,nginx,Php,Nginx,我有一个PHP网站,为每个用户使用子域 我希望能够在内部将cname.otherdomain.com路由到otherdomain.com并将其传递给PHP 现在我有这个 server { listen 80; server_name cname.otherdomain.com; rewrite ^ $scheme://otherdomain.domain.com$request_uri; } server { listen 80 default_server;
cname.otherdomain.com
路由到otherdomain.com
并将其传递给PHP
现在我有这个
server {
listen 80;
server_name cname.otherdomain.com;
rewrite ^ $scheme://otherdomain.domain.com$request_uri;
}
server {
listen 80 default_server;
server_name ~^(?<subdomain>[a-z\_\-\.]+)?\.?domain\.com$ "";
root g:/www;
index index.php;
#error_log /var/log/nginx/debug.log debug;
location ~ (?:application|modules|system) {
deny all;
}
location / {
try_files $uri $uri/ /index.php$request_uri;
}
location ^~ /index.php {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SERVER_NAME $http_host;
fastcgi_pass 127.0.0.1:9999;
}
}
服务器{
听80;
服务器名称cname.otherdomain.com;
重写^$scheme://otherdomain.domain.com$request_uri;
}
服务器{
监听80个默认_服务器;
服务器名称^(?[a-z\\-\.]+)?\.?域\.com$“”;
根g:/www;
index.php;
#错误\u log/var/log/nginx/debug.log debug;
位置(?:应用程序|模块|系统){
否认一切;
}
地点/{
try\u files$uri$uri//index.php$request\u uri;
}
位置^~/index.php{
fastcgi\u split\u path\u info^(.+\.php)(/.+)$;
fastcgi_index.php;
包括fastcgi_参数;
fastcgi\参数脚本\文件名$document\根$fastcgi\脚本\名称;
fastcgi_参数路径_信息$fastcgi_路径_信息;
fastcgi_参数服务器名称$http_主机;
fastcgi_pass 127.0.0.1:9999;
}
}
如果要对用户隐藏此信息,需要将其保存在单个服务器块中。您可以创建一个服务器块,用于捕获子域并将其与fastcgi
位置块一起重用:
server {
server_name ~^cname\.(?<subdomain>.+)\.com$;
...
location ... {
fastcgi_param SERVER_NAME $subdomain.domain.com;
}
}
server {
listen 80 default_server;
...
}
服务器{
服务器名称~^cname\(?。+)\.com$;
...
地点{
fastcgi_参数服务器名称$subdomain.domain.com;
}
}
服务器{
监听80个默认_服务器;
...
}
可以使用include
语句管理nginx
配置文件中的大量重复