Yii 隐藏 index.php(nginx) [ 新手入门 ]
作者:鲁鲁槟 出处:http://www.luluqi.cn/post/default/show-post?id=35
本文版权归作者,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
1、在配置文件 main.php 中添加
'urlManager' => [
//用于URL路径化
'enablePrettyUrl' => true,
//指定是否在URL在保留入口脚本 index.php
'showScriptName' => false,
],
2.1、nginx.conf 配置
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 128k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 32k;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
gzip_disable "MSIE [1-6].";
server_names_hash_bucket_size 128;
client_max_body_size 100m;
client_header_buffer_size 256k;
large_client_header_buffers 4 256k;
server {
listen 80;
server_name localhost;
#你的项目根目录
root "D:/Program Files/phpStudy/WWW";
location / {
index index.html index.htm index.php l.php;
autoindex off;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ \.php(.*)$ {
#你的项目根目录
root "D:/Program Files/phpStudy/WWW";
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
}
}
include vhosts.conf;
}
2.2、vhosts.conf 配置
server {
listen 80;
#你的虚拟主机名
server_name www.luluqi.com ;
#虚拟主机根目录
root "D:/Program Files/phpStudy/WWW/luluyii/web";
location / {
index index.php index.html index.htm;
#nginx ignore index.php
if (!-e $request_filename){
rewrite ^/(.*) /index.php last;
}
}
location ~ \.php(.*)$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
}
}
注:如有疑问或者有更好的方法,请加入 QQ 群 453300767 进行讨论或在下方进行评论。
共 2 条回复
鲁鲁槟 东莞
注册时间:2015-12-02
最后登录:2024-08-09
在线时长:124小时36分
最后登录:2024-08-09
在线时长:124小时36分
- 粉丝110
- 金钱5620
- 威望140
- 积分8260