Skip to content

Instantly share code, notes, and snippets.

@dopsmain
Created May 7, 2021 07:17
Show Gist options
  • Save dopsmain/ba62fb0c3f2ebf2301e7a63dd4910cd5 to your computer and use it in GitHub Desktop.
Save dopsmain/ba62fb0c3f2ebf2301e7a63dd4910cd5 to your computer and use it in GitHub Desktop.
nginx config for opencart 3
server {
root /var/www/demo;
index index.php index.html;
server_name www.demo.com demo.com;
gzip on;
gzip_comp_level 5;
gzip_disable "msie6";
gzip_types text/plain text/css application/json application/x-javascript application/javascript text/xml application/xml application/xml+rss text/javascript;
location = /sitemap.xml {
rewrite ^(.*)$ /index.php?route=feed/google_sitemap break;
}
location = /googlebase.xml {
rewrite ^(.*)$ /index.php?route=feed/google_base break;
}
location / {
try_files $uri $uri/ @opencart;
}
location @opencart {
rewrite ^/(.*)$ /index.php?_route_=$1 last;
}
location ~* \.(engine|inc|info|ini|install|log|make|module|profile|test|po|sh|.*sql|theme|tpl(\.php)?|xtmpl)$|^(\..*|Entries.*|Repository|Root|Tag|Template)$|\.php_ {
deny all;
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /apple-touch-icon.png {
log_not_found off;
access_log off;
}
location = /apple-touch-icon-precomposed.png {
log_not_found off;
access_log off;
}
location ~* \.(?:3gp|gif|jpg|jpe?g|png|ico|wmv|avi|asf|asx|mpg|mpeg|mp4|pls|mp3|mid|wav|swf|flv|txt|js|css|exe|zip|tar|rar|gz|tgz|bz2|uha|7z|doc|docx|xls|xlsx|pdf|iso|woff|woff2|eot|otf|ttf)$ {
expires max;
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
}
location ~ /\. {
access_log off;
log_not_found off;
deny all;
}
location ~ ~$ {
access_log off;
log_not_found off;
deny all;
}
location ~* /(?:cache|logs|image|download)/.*\.php$ {
deny all;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location ~* \.(eot|otf|ttf|woff)$ {
add_header Access-Control-Allow-Origin *;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/www;
}
location ~ .php$ {
if (!-e $request_filename) {
rewrite ^/(.+)$ /index.php?_route_=$1 last;
}
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
try_files $uri =404;
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
listen 443 ssl;
ssl_certificate /etc/letsencrypt/live/demo.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/demo.com/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
}
server {
if ($host = www.demo.com) {
return 301 https://$host$request_uri;
}
if ($host = demo.com) {
return 301 https://$host$request_uri;
}
listen 80;
server_name www.demo.com demo.com;
return 404;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment