服务器之家:专注于服务器技术及软件下载分享
分类导航

云服务器|WEB服务器|FTP服务器|邮件服务器|虚拟主机|服务器安全|DNS服务器|服务器知识|Nginx|IIS|Tomcat|

服务器之家 - 服务器技术 - Nginx - PHP的Symfony和CodeIgniter框架的Nginx重写规则配置

PHP的Symfony和CodeIgniter框架的Nginx重写规则配置

2019-11-07 15:01goldensun Nginx

这篇文章主要介绍了PHP的Symfony和CodeIgniter框架的Nginx重写规则配置,文中截取配置中关键的一些rewrite写法进行讲解,需要的朋友可以参考下

Symfony
Symfony国外很流行的php框架,目前国内用的相对较少,但是一定会在国内火起来. nginx重写规则如下

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
server {
 server_name zzvips.com www.zzvips.com;
 root /data/site/www.zzvips.com;
location / {
 # try to serve file directly, fallback to rewrite
 try_files $uri @rewriteapp;
 }
location @rewriteapp {
 # rewrite all to app.php
 rewrite ^(.*)$ /app.php/$1 last;
 }
location ~ ^/(app|app_dev|config).php(/|$) {
 fastcgi_pass unix:/var/run/php5-fpm.sock; # 改成你对应的FastCGI
 fastcgi_split_path_info ^(.+.php)(/.*)$;
 include fastcgi_params;
 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
 fastcgi_param HTTPS off;
 }
error_log /data/logs/nginx/www.zzvips.com_error.log;
 }

 
重启nginx即可

 

CodeIgniter
CodeIgniter,即被很多人简称为CI的高人气PHP框架,其中文社区也比较活跃,来看一下CI的rewrite写法:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
server {
 listen 80;
 server_name zzvips.com www.zzvips.com;
root /data/site/www.zzvips.com;
 index index.php;
 error_log log/error.log;
# set expiration of assets to MAX for caching
 location ~* .(ico|css|js|gif|jpe?g|png)(?[0-9]+)?$ {
 expires max;
 log_not_found off;
 }
# main codeigniter rewrite rule
 location / {
 try_files $uri $uri/ /index.php;
 }
# php parsing
 location ~ .php$ {
 root /data/site/zzvips.com/;
 try_files $uri =404;
 fastcgi_pass unix:/tmp/php5-fpm.sock; # 改成对应的FastCGI
 fastcgi_index index.php;
 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
 include fastcgi_params;
 fastcgi_buffer_size 128k;
 fastcgi_buffers 256 4k;
 fastcgi_busy_buffers_size 256k;
 fastcgi_temp_file_write_size 256k;
 }
}


修改CI(CodeIgniter )配置文件config.php

?
1
2
3
$config['base_url'] = "//www.zzvips.com/";
 $config['index_page'] = "";
 $config['uri_protocol'] = "REQUEST_URI";

 

延伸 · 阅读

精彩推荐