nginx 配置虚拟目录并且url 重定向
server {
#侦听80端口
listen 8090;
#定义使用www.xx.com访问
server_name 127.0.0.1;
#设定本虚拟主机的访问日志
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
root /home/lxy/www/cs/; #定义服务器的默认网站根目录位置
#默认请求
location / {
index index.php index.html index.htm; #定义首页索引文件的名称
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php?$1 last;
break;
}
}
#PHP 脚本请求全部转发到 FastCGI处理. 使用FastCGI默认配置.
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /home/lxy/www/cs/$fastcgi_script_name;
include fastcgi_params;
}
#禁止访问 .htxxx 文件
location ~ /\.ht {
deny all;
}
}
其中 if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php?$1 last;
break;
} i
就是对 url 重写,重写后的url 可以通过 http://127.0.0.1:8090/index.php/Page/index 访问web 网站