phpinfo
server {
listen 80;
server_name phpinfo.com;
root /home/www/test;
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;
}
}
如果cgi_pass是连接php-fpm.sock,记得要设置php-fpm.conf里面的
listen.owner = nginx
listen.group = nginx
listen.mode = 0660
server {
listen 80;
server_name localhost;
root /data/php/phpinfo;
index index.php index.html;
location ~ \.php$ {
fastcgi_pass unix:/data/php/run/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
CI框架
server {
listen 80;
server_name dev.ci.com;
index index.php index.html index.htm;
root /lhdata/wwwroot/ci-api.benting.com.cn/www;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ [^/]\.php(/|$) {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
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;
}
}
lumen框架
server {
listen 80;
server_name ???.com.cn;
access_log /???_nginx.log combined;
index index.php index.html index.htm;
root /???/[lumen_project]/public;
location / {
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}
}
# 添加一些跨域配置
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept";
add_header Access-Control-Allow-Methods "GET, POST, OPTIONS";
location ~ [^/]\.php(/|$) {
#fastcgi_pass remote_php_ip:9000;
fastcgi_pass unix:/dev/shm/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
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;
}
}
laravel框架
server {
listen 80;
server_name test.laravel.com;
root /home/www/gitosc/laravel_blog/public;
index index.html index.htm index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
sendfile off;
client_max_body_size 100m;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors off;
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
}
location ~ /\.ht {
deny all;
}
}
整理常用PHP框架重写规则
ThinkPHP5重写规则
location / {
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}
}
Laravel或Lumen重写规则
location / {
try_files $uri $uri/ /index.php?$query_string;
}
CI框架重写规则
location / {
try_files $uri $uri/ /index.php?$query_string;
}
Yii2重写规则
location / {
if (!-f $request_filename){
rewrite ^/(.*)$ /index.php?/$1 last;
break;
}
}
希望大家会有所帮助,自己需要的时候也可以回头查查很方便,谢谢