PHP's Symfony and CodeIgniter framework's Nginx override rule configuration

  • 2020-05-10 23:30:52
  • OfStack

Symfony
The php framework, which is very popular abroad, is currently used relatively little in China, but 1 is bound to take off at home. nginx rewrite rules are as follows


server {
 server_name ofstack.com www.ofstack.com;
 root /data/site/www.ofstack.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; #  Change it to your equivalent 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.ofstack.com_error.log;
 }

 
Just restart nginx

CodeIgniter
CodeIgniter, the popular PHP framework known by many people as CI for short, also has an active Chinese community. Let's take a look at the rewrite version of CI:


server {
 listen 80;
 server_name ofstack.com www.ofstack.com;
root /data/site/www.ofstack.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/ofstack.com/;
 try_files $uri =404;
 fastcgi_pass unix:/tmp/php5-fpm.sock; #  I'm gonna change it to 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;
 }
}


Modify the CI(CodeIgniter) configuration file config.php


$config['base_url'] = "//www.ofstack.com/";
 $config['index_page'] = "";
 $config['uri_protocol'] = "REQUEST_URI";


Related articles: