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

时间:2021-05-19

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

server { server_name jb51.net ; root /data/site/;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/_error.log; }


重启nginx即可

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

server { listen 80; server_name jb51.net ;root /data/site/; 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/jb51.net/; 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'] = "https:///"; $config['index_page'] = ""; $config['uri_protocol'] = "REQUEST_URI";

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章