nginx配置laravel 框架支持pathinfo路由模式:
vi /usr/local/nginx/conf/vhost/dev.mbot.com.conf
server {
listen 80;
listen 443 ssl; # 支持ssl https
server_name dev.mbot.com; # 项目的域名
#rewrite ^(.*)$ https://$host$1 permanent;
access_log /data/wwwlogs/dev.mbot.com_nginx.log combined; # 该项目的nginx运行日志文件
index index.html index.htm index.php; // 入口脚本索引文件
root /data/wwwroot/mbot/public; // laravel 框架的入库脚本位置目录
# 两个ssl 证书
# 保存的绝对路径 /usr/local/nginx/conf/ssl/mbot; 实际配置一般习惯使用相对路径
ssl_certificate ssl/mbot/server.crt;
ssl_certificate_key ssl/mbot/server_nopwd.key;
location ~ .*\.(wma|wmv|asf|mp3|mmf|zip|rar|jpg|gif|png|swf|flv|mp4)$ {
valid_referers none blocked *.mbot.com dev.mbot.com;
if ($invalid_referer) {
return 403;
}
}
location / {
index index.htm index.html index.php;
if (!-e $request_filename){
rewrite ^/(.*)$ /index.php?s=$1 last; # 路由规则
break;
}
# resultful api中都会有一个这样的请求 直接返回即可
if ($request_method = 'OPTIONS'){
return 200;
}
}
location ~ /.*\.php/ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
rewrite ^(.*?/?)(.*\.php)(.*)$ /$2?s=$3 last; # 路由规则
break;
}
location ~ .*\.(php|php5|cgi|pl)?$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {
expires 30d;
access_log off;
}
location ~ .*\.(js|css)?$ {
expires 7d;
access_log off;
}
location ~ /\.ht {
deny all;
}
}
网友评论