简单配置nginx使之支持pathinfo(nginx配置dist)
admin2024-08-14 10:15:28Linux运维
1.pathinfo参考,复制全部,修改域名目录等
server {
listen 80;
server_name xx.shnne.com;
access_log /xx/xx/xx/access_shnne.log;
root /xx/xxx/shnne;
location / {
index index.php index.html;
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=/$1 last;
break;
}
}
location ~* \.php {
fastcgi_pass unix:/tmp/php-fpm.socket;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
include fastcgi_params;
}
}
或者
server {
listen 80;
server_name xx.shnne.com;
access_log /xx/xx/xx/access_shnne.log;
root /xx/xxx/shnne;
location / {
index index.html index.php;
}
if (!-e $request_filename) {
rewrite ^/(.*) /index.php/$1 last;
}
location ~ .+\.php($|/) { #修改这里
fastcgi_pass unix:/tmp/php-fpm.socket;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
include fastcgi_params;
}
}
2.伪静态url重写
server {
listen 80;
server_name www.shnne.com;
access_log /data/log/nginx/access_shnne.log;
root /data/web/shnne/public;
location / {
index index.php index.html;
}
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;
}
if (!-e $request_filename) {
rewrite ^/(.*\.(js|ico|gif|jpg|png|css|bmp|html|xls)$) /$1 last;
rewrite ^/(.*) /index.php?$1 last;
}
}