Skip to content

Instantly share code, notes, and snippets.

@ryaan-anthony
Created April 16, 2015 16:45
Show Gist options
  • Select an option

  • Save ryaan-anthony/4162ad40f15e57e7ccdf to your computer and use it in GitHub Desktop.

Select an option

Save ryaan-anthony/4162ad40f15e57e7ccdf to your computer and use it in GitHub Desktop.
Nginx magento host config
server {
listen 80 default;
listen 443 default ssl;
#ssl_certificate /etc/pki/tls/certs/localhost.crt;
#ssl_certificate_key /etc/pki/tls/private/localhost.key;
server_name www._HOSTNAME_ _HOSTNAME_;
root /home/ccardi/public_html;
access_log /var/log/nginx/_HOSTNAME_-access.log main buffer=16k;
error_log /var/log/nginx/_HOSTNAME_-error.log error;
index index.html index.php;
location = /nginx_stub_status {
stub_status on;
allow 172.24.32.138;
allow 127.0.0.1;
deny all;
}
# Rewrite files.php/ to file.php
location ~* .php/ { rewrite ^(.*.php)/ $1 last; }
# Send client IP to the proxy instead of localhost
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
# Direct 404s to the root
error_page 404 = @error;
location @error {
rewrite .* / permanent;
}
# Deny access to hidden files
location ~ /\. {deny all;}
#Magento Default Deny
location ~ /errors/(.+)\.xml$ {
deny all;
}
location ~ ^/app/ {
deny all;
}
location ~ ^/RELEASE_NOTES.txt {
deny all;
}
location ~ ^/downloader/template/ {
deny all;
}
location ~ ^/pkginfo/ {
deny all;
}
location ~ ^/var/backups/ {
deny all;
}
location ~ ^/includes/ {
deny all;
}
location ~ ^/lib/ {
deny all;
}
location ~ ^/downloader/(.+)\.(cfg|ini|xml)$ {
deny all;
}
#Magento API2 Rewrite
location ^/api {
rewrite ^/api/rest /api.php?type=rest break;
}
# Allow fonts from other origins
location ~* \.(eot|ttf|woff)$ {
add_header Access-Control-Allow-Origin *;
}
location /index { try_files $uri @fcgi_nocache; }
location /checkout { try_files $uri @fcgi_nocache; }
location /downloader { try_files $uri $uri/ index.php; }
# Direct access files, no caching on server
#swf/flv
location ~* ^.+\.(xml|htm|tar|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|pdf|txt|tar|wav|bmp|rtf|js|flv|swf)$ {
#log_not_found off;access_log off; expires max;
#add_header Cache-Control public;
root /home/ccardi/public_html;
}
# PHP root index
location / {
try_files $uri $uri/ @fcgi_nocache;
}
# Execute php scripts
location ~ \.php$ {
expires off; ## Do not cache dynamic content
fastcgi_pass unix:/var/run/php-fpm/_HOSTNAME_.sock;
fastcgi_index index.php;
fastcgi_param HTTPS $fastcgi_https;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params; ## See /etc/nginx/fastcgi_params
}
# Magento - No caching
location @fcgi_nocache {
fastcgi_pass unix:/var/run/php-fpm/_HOSTNAME_.sock;
fastcgi_param HTTPS $fastcgi_https;
include fastcgi_params;
fastcgi_read_timeout 18000;
fastcgi_connect_timeout 180;
fastcgi_send_timeout 180;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
fastcgi_intercept_errors off;
fastcgi_param SCRIPT_FILENAME $document_root/index.php;
fastcgi_param SCRIPT_NAME /index.php;
fastcgi_keep_conn on; # NGINX 1.1.14
fastcgi_temp_path /var/tmp 1 2;
send_timeout 120;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment