Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save cesarmarinhorj/693790656d20f67343a8b83185942c4e to your computer and use it in GitHub Desktop.
Save cesarmarinhorj/693790656d20f67343a8b83185942c4e to your computer and use it in GitHub Desktop.
Yii2 Basic Nginx Host Config Example
server {
listen 80;
server_name www.hostname.com;
rewrite ^(.+)$ http://hostname.com permanent;
}
server {
charset utf-8;
client_max_body_size 128M;
listen 80; ## listen for ipv4
server_name hostname.com www.hostname.com;
root /var/www/hostname.com/web;
index index.php;
access_log /var/log/nginx/hostname.com.access.log;
error_log /var/log/nginx/hostname.com.error.log;
location / {
# Redirect everything that isn't a real file to index.php
try_files $uri $uri/ /index.php?$args;
}
# uncomment to avoid processing of calls to non-existing static files by Yii
#location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
# try_files $uri =404;
#}
#error_page 404 /404.html;
location ~ \.php$ {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
include fastcgi_params;
fastcgi_read_timeout 600s;
}
location ~ /\.(git) {
deny all;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment