You are viewing revision #1 of this wiki article.
This version may not be up to date with the latest version.
You may want to view the differences to the latest version.
The full configuration is here, let's explain it later.
server {
listen 80;
server_name example.com www.example.com;
charset utf-8;
access_log logs/example.access.log main;
location / {
root /home/yeegt/yiigt;
index index.php;
try_files $uri $uri/ /index.php?$args;
}
location ~ ^/protected/ {
deny all;
}
location ~*.(js|jpg|jpeg|gif|png|ico)$ {
root /home/example/yii-app;
expires 356d;
add_header Cache-Control public;
}
location ~ \.php$ {
root /home/example/yii-app;
fastcgi_pass 127.0.0.1:9010;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /home/example/yii-app$fastcgi_script_name;
include fastcgi_params;
set $path_info $request_uri;
if ($request_uri ~ "^(.*)(\?.*)$") {
set $path_info $1;
}
fastcgi_param PATH_INFO $path_info;
}
}
Duplicate?
http://www.yiiframework.com/wiki/15/how-to-hide-index-php-on-nginx
Not a duplicate
@samdark, this is not a duplicate posting, as the one that you linked only shows a partial config, and does not reference any configuration to disable folders that should be inaccessible (though best practice is to deploy /protected/ in a non-web-accessible folder).
The config as-posted needs a bit of tweaking, but is a good start.
Note on example domain name
"example.com" or similar should be used. See http://www.iana.org/domains/example/.
Wrong conf.d/yiiframework.conf
I have been struggling with moving yiiframework.conf to conf.d/. Since I'm new to Nginx, it didn't work creating yiiframework.conf with just the location configuraiton. As far as I figured out, conf.d files are autoloaded by nginx, so they have to be complete config files. Creating a separate directory to my "global" includes worked.
So:
1) create /etc/nginx/globals
2) create restrictions.conf and yiiframework.conf there
3) reference those files from your server config section.
That's it!
fastcgi_split_path_info is useless
fastcgi_split_path_info just defines a variable, it is useless without passing the parameters to PHP:
fastcgi_split_path_info ^(.+.php)(.*)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
Here is my version of Nginx configuration:
http://yii.grik.net/index.php?title=Apache_and_Nginx_configurations
avoid unix sockets
There is a linux-specific issue for unix sockets, don't use them to connect FPM and Nginx or you will get errors on load.
There were a couple of long threads between Sysoev and Nigmatulin on this topic a few years ago.
Local sockets still an issue?
@grigori are you possibly referring to this? Does it still stand? I've got a couple of CentOS setups running (which means heavily patched 2.6.18 kernels) relying on local sockets a lot for both, MySQL and php-fpm. Haven't had any problems so far.
Re: Local sockets still an issue?
Yes, they are and will as far as I know. I'll ask Andrei or Tony if they heard anything about a fix in the linux kernel, but I don't rely on this.
You may not experience any problem until some load, and you won't see them - some users will.
Also, it is important to set cgi.fix_pathinfo 0 in php.ini to avoid a serious security issue and improve performance.
I committed a safe and flexible Nginx configuration to the yii guide, it should get published with 1.1.9
Re[2]: Local sockets still an issue?
Hm, that is worrying to hear. Especially since I've managed to save some precious memory that way. I think I'm going to set up a test system soon and see if I'll be able to reproduce the issue.
Regarding the rest: Isn't that part of the nginx Pitfalls already?
Yii + Nginx + SSL
Thanks for the article. I wondering if you've experienced any strange issues in regards to using Nginx and SSL. I have an unsolved blog post that maybe you could help me with:
http://www.yiiframework.com/forum/index.php?/topic/24169-https-302-redirect-issue-when-posting-form/page__p__117336__fromsearch__1#entry117336
Please consider to use a wider list of file types, because glyphicons can be unvisible due to access problems. My list is:
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.