Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating nginx magento2.conf according to latest version of nginx.conf in Magento 2 Open Source repository #37

Merged
merged 1 commit into from
Oct 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions nginx/etc/nginx/available.d/magento2.conf
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ location / {
}

location /pub/ {
location ~ ^/pub/media/(downloadable|customer|import|theme_customization/.*\.xml) {
location ~ ^/pub/media/(downloadable|customer|import|custom_options|theme_customization/.*\.xml) {
deny all;
}
alias $MAGE_ROOT/pub/;
Expand All @@ -63,18 +63,18 @@ location /static/ {
# expires max;

# Remove signature of the static files that is used to overcome the browser cache
location ~ ^/static/version {
rewrite ^/static/(version[^/]+/)?(.*)$ /static/$2 last;
location ~ ^/static/version\d*/ {
rewrite ^/static/version\d*/(.*)$ /static/$1 last;
}

location ~* \.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2|json)$ {
location ~* \.(ico|jpg|jpeg|png|gif|svg|svgz|webp|avif|avifs|js|css|eot|ttf|otf|woff|woff2|html|json|webmanifest)$ {
add_header Cache-Control "public";
add_header X-Frame-Options "SAMEORIGIN";
add_header Access-Control-Allow-Origin "*"; # Allow use from CDN origin
expires +1y;

if (!-f $request_filename) {
rewrite ^/static/?(.*)$ /static.php?resource=$1 last;
rewrite ^/static/(version\d*/)?(.*)$ /static.php?resource=$2 last;
}
}

Expand All @@ -84,11 +84,11 @@ location /static/ {
expires off;

if (!-f $request_filename) {
rewrite ^/static/?(.*)$ /static.php?resource=$1 last;
rewrite ^/static/(version\d*/)?(.*)$ /static.php?resource=$2 last;
}
}
if (!-f $request_filename) {
rewrite ^/static/?(.*)$ /static.php?resource=$1 last;
rewrite ^/static/(version\d*/)?(.*)$ /static.php?resource=$2 last;
}
add_header X-Frame-Options "SAMEORIGIN";
}
Expand All @@ -106,7 +106,7 @@ location /media/ {
deny all;
}

location ~* \.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2)$ {
location ~* \.(ico|jpg|jpeg|png|gif|svg|svgz|webp|avif|avifs|js|css|eot|ttf|otf|woff|woff2)$ {
add_header Cache-Control "public";
add_header X-Frame-Options "SAMEORIGIN";
expires +1y;
Expand All @@ -133,6 +133,16 @@ location /media/import/ {
deny all;
}

location /media/custom_options/ {
deny all;
}

location /errors/ {
location ~* \.xml$ {
deny all;
}
}

location ~* ^/dev/tests/acceptance/utils($|/) {
root $MAGE_ROOT;

Expand Down Expand Up @@ -189,6 +199,6 @@ gzip_types
gzip_vary on;

# Banned locations (only reached if the earlier PHP entry point regexes don't match)
location ~* (\.php$|\.htaccess$|\.git) {
location ~* (\.php$|\.phtml$|\.htaccess$|\.htpasswd$|\.git) {
deny all;
}