登录  /  注册

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

不言
发布: 2018-06-14 15:13:56
原创
1278人浏览过

这篇文章主要介绍了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

$config['base_url'] = "//www.php.cn/";
 $config['index_page'] = "";
 $config['uri_protocol'] = "REQUEST_URI";
登录后复制

以上就是本文的全部内容,希望对大家的学习有所帮助,更多相关内容请关注PHP中文网!

相关推荐:

关于CI框架中$this->load->library()的用法分析

如何基于CodeIgniter框架实现购物车功能

以上就是关于PHP的Symfony和CodeIgniter框架的Nginx重写规则配置的详细内容,更多请关注php中文网其它相关文章!

智能AI问答
PHP中文网智能助手能迅速回答你的编程问题,提供实时的代码和解决方案,帮助你解决各种难题。不仅如此,它还能提供编程资源和学习指导,帮助你快速提升编程技能。无论你是初学者还是专业人士,AI智能助手都能成为你的可靠助手,助力你在编程领域取得更大的成就。
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2024 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号