Last active
October 10, 2017 02:25
-
-
Save aqlx86/bcde7eefcaf2fa365936 to your computer and use it in GitHub Desktop.
Yii +Nginx + PHP-FPM configuration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| server { | |
| set $host_path "/var/www/yoursite.com"; | |
| access_log /var/www/yoursite.com/log/access.log main; | |
| server_name yoursite.com www.yoursite.com; | |
| root $host_path/htdocs; | |
| set $yii_bootstrap "index.php"; | |
| # define charset | |
| charset utf-8; | |
| location / { | |
| index index.html $yii_bootstrap; | |
| try_files $uri $uri/ /$yii_bootstrap?$args; | |
| } | |
| # deny access to protected directories | |
| location ~ ^/(protected|framework|themes/w+/views) { | |
| deny all; | |
| } | |
| #avoid processing of calls to unexisting static files by yii | |
| location ~ .(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ { | |
| try_files $uri =404; | |
| } | |
| # prevent nginx from serving dotfiles (.htaccess, .svn, .git, etc.) | |
| location ~ /. { | |
| deny all; | |
| access_log off; | |
| log_not_found off; | |
| } | |
| # php-fpm configuration using socket | |
| location ~ .php { | |
| fastcgi_split_path_info ^(.+.php)(.*)$; | |
| #yii catches the calls to unexising PHP files | |
| set $fsn /$yii_bootstrap; | |
| if (-f $document_root$fastcgi_script_name){ | |
| set $fsn $fastcgi_script_name; | |
| } | |
| fastcgi_pass unix:/tmp/php5-fpm.sock; | |
| include fastcgi_params; | |
| fastcgi_param SCRIPT_FILENAME $document_root$fsn; | |
| #PATH_INFO and PATH_TRANSLATED can be omitted, but RFC 3875 specifies them for CGI | |
| fastcgi_param PATH_INFO $fastcgi_path_info; | |
| fastcgi_param PATH_TRANSLATED $document_root$fsn; | |
| ## Tweak fastcgi buffers, just in case. | |
| fastcgi_buffer_size 128k; | |
| fastcgi_buffers 256 4k; | |
| fastcgi_busy_buffers_size 256k; | |
| fastcgi_temp_file_write_size 256k; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Does this handle requesting other yii bootstrap files like index-test.php? I have a pretty similar configuration with homestead and I swear I got it working one time because I was adding codeception to our codebase but all of sudden, the next day all requests started to fail. The location block + try_files at the top would never match the correct file when using path based URLs (index-test.php/site/index would fail for example) so requests would always default to $yii_bootstrap (index.php).
EDIT:
Never mind, I think I figured it out.