应开发需求,网站数目众多,要用一个虚拟主机配置文件来控制所有的站点,将nginx伪静态重写规则写在对应的web目录下面 让nginx去调用 文件名随意,这里定义为.htaccess
调用过程中需要给web这个目录做一个变量,在这个变量调用这边实在是过不去,求铭哥指点
配置如下
server
{
listen 80;
server_name ~^(.+)\.(.+)\.(com|cn|net|com.cn|org|net.cn)$;
index index.html index.htm index.php;
set $www_root $1.$2.$3;
root /data/www/$www_root;
include /data/www/$www_root/.htaccess; 这一行就是调用文件的那一行,问题在于怎么去调用server_name 匹配出来的域名进行目录的对应呢。
access_log /tmp/access.log ;
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/tmp/www.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
location /Public {
alias /data/www/Public/;
}
location /Templates {
alias /data/www/Templates/;
}
}
调用过程中需要给web这个目录做一个变量,在这个变量调用这边实在是过不去,求铭哥指点
配置如下
server
{
listen 80;
server_name ~^(.+)\.(.+)\.(com|cn|net|com.cn|org|net.cn)$;
index index.html index.htm index.php;
set $www_root $1.$2.$3;
root /data/www/$www_root;
include /data/www/$www_root/.htaccess; 这一行就是调用文件的那一行,问题在于怎么去调用server_name 匹配出来的域名进行目录的对应呢。
access_log /tmp/access.log ;
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/tmp/www.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
location /Public {
alias /data/www/Public/;
}
location /Templates {
alias /data/www/Templates/;
}
}
0
内容是 nginx的伪静态 我通过这样的写法已经实现了域名正常访问到对应的目录,但是伪静态规则的调用这里用include 调用存放在web目录下的规则的时候 中间 根据域名定义的目录,不知道能不能用变量实现
阿铭 发表于 2016-6-30 14:29
server_name 虽然支持正则,但是不支持你这样的写法 你的.htaccess内容是什么
内容是 nginx的伪静态 我通过这样的写法已经实现了域名正常访问到对应的目录,但是伪静态规则的调用这里用include 调用存放在web目录下的规则的时候 中间 根据域名定义的目录,不知道能不能用变量实现
0
rewrite ^(.*)/index.html$ $1/index.php last;
这是.htaccess文件中的重写规则
阿铭 发表于 2016-6-30 14:39
你发一个具体的文件内容出来。
rewrite ^(.*)/index.html$ $1/index.php last;
这是.htaccess文件中的重写规则
编辑回复