这篇文章主要介绍了php的symfony和codeigniter框架的nginx重写规则配置,文中截取配置中关键的一些rewrite写法进行讲解,需要的朋友可以参考下
Symfony
Symfony国外很流行的php框架,目前国内用的相对较少,但是一定会在国内火起来. nginx重写规则如下
server {
server_name php.cn www.php.cn;
root /data/site/www.php.cn;
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.php.cn_error.log;
}重启nginx即可
CodeIgniter
CodeIgniter,即被很多人简称为CI的高人气PHP框架,其中文社区也比较活跃,来看一下CI的rewrite写法:
server {
listen 80;
server_name php.cn www.php.cn;
root /data/site/www.php.cn;
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/php.cn/;
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
立即学习“PHP免费学习笔记(深入)”;
$config['base_url'] = "//www.php.cn/"; $config['index_page'] = ""; $config['uri_protocol'] = "REQUEST_URI";
以上就是本文的全部内容,希望对大家的学习有所帮助,更多相关内容请关注PHP中文网!
相关推荐:
关于CI框架中$this->load->library()的用法分析
以上就是关于PHP的Symfony和CodeIgniter框架的Nginx重写规则配置的详细内容,更多请关注php中文网其它相关文章!
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号