nginx如何支持TP框架配置的nginx.conf

本文介绍了一个ThinkPHP框架的Nginx配置案例,包括URL重写、静态资源缓存策略等内容,有助于提高网站性能及用户体验。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  1. server {  
  2.         listen       80;  
  3.         server_name  localhost;  
  4.         charset utf-8;  
  5.         access_log  logs/host.access.log  main;  
  6.         root /var/www/html/thinkphp/public;  
  7.         index  index.html index.htm index.php;  
  8.         location / {  
  9.             if (!-e $request_filename) {  
  10.                 rewrite ^(.*)$ /index.php?s=$1 last;  
  11.                 break;  
  12.             }  
  13.         }  
  14.         error_page   500 502 503 504  /50x.html;  
  15.         location = /50x.html {  
  16.             root   html;  
  17.         }  
  18.         location ~ \.php$ {  
  19.            fastcgi_pass   127.0.0.1:9000;  
  20.            fastcgi_index index.php;  
  21.            include fastcgi_params;  
  22.            set $real_script_name $fastcgi_script_name;  
  23.            if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {  
  24.                set $real_script_name $1;  
  25.                set $path_info $2;  
  26.            }  
  27.            fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;  
  28.            fastcgi_param SCRIPT_NAME $real_script_name;  
  29.            fastcgi_param PATH_INFO $path_info;  
  30.         }  
  31.         location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|ico)$ {  
  32.             expires 30d;  
  33.             access_log off;  
  34.         }  
  35.         location ~ .*\.(js|css)?$ {  
  36.             expires 7d;  
  37.             access_log off;  
  38.        }  
  39. }  
注意:在TP框架的配置文件中一定要加上‘URL_MODEL’=>2

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值