I recently upgraded from 2.3.5-p1 to 2.4.0 and everything was working fine. I then upgraded Magento 2.4.0 to 2.4.2, however this time I got 404 Error on the website. Upon checking the logs I found that now Magento is loading data from website.com/pub
rather then website.com
.
I think Magento recently changed docroot to pub
and mentioned here
But I am not sure how will this work, I changed root
in nginx.conf and added pub
. But it didn’t work.
My nginx.conf file is given below:
server {
listen 80 backlog=65535; server_name website.com www.website.com;
#root /var/www/website;
return 301 https://www.website.com$request_uri; } server {
listen 443 ssl http2; server_name website.com; keepalive_timeout 70; root /var/www/website; return 301 https://www.website.com$request_uri;
gzip on; ssl_certificate /etc/letsencrypt/live/website.com/fullchain.pem; # managed by Certbot ssl_certificate_key /etc/letsencrypt/live/website.com/privkey.pem; # managed by Certbot ssl_protocols TLSv1.2; ssl_ciphers EECDH+AESGCM:EDH+AESGCM:ECDHE-RSA-AES128-GCM-SHA256:AES256+EECDH:DHE-RSA-AES128-GCM-SHA256:AES256+EDH:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA:DES-CBC3-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!PSK:!RC4:!3DES; ssl_dhparam /etc/nginx/conf.d/dhparam.pem; ssl_prefer_server_ciphers on; ssl_session_tickets off; ssl_session_cache shared:SSL:10m; } server {
listen 443 ssl http2 backlog=65535; server_name www.website.com; root /var/www/website; index index.php;
gzip on; pagespeed off;
ssl_certificate /etc/letsencrypt/live/website.com/fullchain.pem; # managed by Certbot ssl_certificate_key /etc/letsencrypt/live/website.com/privkey.pem; # managed by Certbot ssl_protocols TLSv1.2; ssl_ciphers EECDH+AESGCM:EDH+AESGCM:ECDHE-RSA-AES128-GCM-SHA256:AES256+EECDH:DHE-RSA-AES128-GCM-SHA256:AES256+EDH:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA:DES-CBC3-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!PSK:!RC4:!3DES; ssl_dhparam /etc/nginx/conf.d/dhparam.pem; ssl_prefer_server_ciphers on; ssl_session_tickets off; ssl_session_cache shared:SSL:10m;
#OCSP ssl_trusted_certificate /etc/letsencrypt/live/website.com/chain.pem; ssl_stapling on; ssl_stapling_verify on;
#add_header X-Frame-Options "DENY"; add_header X-Content-Type-Options nosniff;
charset UTF-8; autoindex off; access_log /var/log/nginx/website.access.log; error_log /var/log/nginx/website.error.log;
error_page 419 = @magento;
location ~ /\. { deny all; }
location / {
root /var/www/website;
index index.php index.html;
add_header Strict-Transport-Security "max-age=63072000; includeSubdomains" always;
add_header 'Access-Control-Allow-Origin' '*';
#NAXSI
#include /etc/nginx/website_naxsi.conf;
location /pub/ {
location /pub/media/ {
location /pub/media/customer/ {
deny all;
}
location /pub/media/downloadable/ {
deny all;
}
location /pub/media/import/ {
deny all;
}
location /pub/media/custom_options/ {
deny all;
}
location ~ /pub/media/theme_customization/.*\.xml$ {
deny all;
}
try_files $uri $uri/ /pub/get.php?$args;
location ~* \.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2|html|json)$ {
add_header Cache-Control "public";
add_header X-Frame-Options "SAMEORIGIN";
expires +1y;
try_files $uri $uri/ /pub/get.php?$args;
}
location ~* \.(zip|gz|gzip|bz2|csv|xml)$ {
add_header Cache-Control "no-store";
add_header X-Frame-Options "SAMEORIGIN";
expires off;
try_files $uri $uri/ /pub/get.php?$args;
}
}
location /pub/static/ {
#if ($MAGE_MODE = "production") {
# expires max;
#}
location ~ ^/pub/static/version {
rewrite ^/pub/static/(version\d*/)?(.*)$ /pub/static/$2 last;
}
location ~* \.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2)$ {
add_header Cache-Control "public";
add_header X-Frame-Options "SAMEORIGIN";
expires +1y;
if (!-f $request_filename) {
rewrite ^/pub/static/(version\d*/)?(.*)$ /pub/static.php?resource=$2 last;
}
}
location ~* \.(zip|gz|gzip|bz2|csv|xml)$ {
add_header Cache-Control "no-store";
add_header X-Frame-Options "SAMEORIGIN";
expires off;
if (!-f $request_filename) {
rewrite ^/pub/static/(version\d*/)?(.*)$ /pub/static.php?resource=$2 last;
}
}
if (!-f $request_filename) {
rewrite ^/pub/static/(version\d*/)?(.*)$ /pub/static.php?resource=$2 last;
}
add_header X-Frame-Options "SAMEORIGIN";
}
add_header X-Frame-Options "SAMEORIGIN";
location ~ ^/pub/errors/.*\.(xml|phtml)$ {
deny all;
}
location /pub/errors/ {
try_files $uri =404;
}
location = /pub/cron.php {
deny all;
}
}
location ~ (index|get|static|report|404|503|phpinfo)\.php$ {
return 419;
}
#if (-e $request_filename) { return 403; }
if (!-e $request_filename) { rewrite / /index.php last; }
#rewrite / /index.php last;
}
location /.user.ini {
deny all; } #location @handler { rewrite / /index.php last; } #location ~* .php/ { rewrite ^(.*.php)/ $1 last; }
location @magento {
root /var/www/website;
#fastcgi_pass php-fpm;
fastcgi_pass unix:/var/run/php-fpm/website.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_split_path_info ^(.*\.php)(/.*)?$;
#if (!-e $request_filename) { rewrite / /index.php last; }
if ($request_uri ~ ^/([^?]*)\.php($|\?)) { return 302 /$1?$args; }
#fastcgi_split_path_info ^(.+\.php)(/.+)$;
try_files $uri = 404;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_intercept_errors on;
fastcgi_param PHP_FLAG "session.auto_start=off \n suhosin.session.cryptua=off";
fastcgi_connect_timeout 600s;
fastcgi_read_timeout 600s;
fastcgi_buffers 16 256k;
fastcgi_buffer_size 256k;
include fastcgi_params; }
gzip_disable "msie6"; gzip_comp_level 6; gzip_min_length 1100; gzip_buffers 16 8k; gzip_proxied any; gzip_types text/plain text/css text/js text/xml text/javascript application/javascript application/x-javascript application/json application/xml application/xml+rss image/svg+xml; gzip_vary on;
# Banned locations (only reached if the earlier PHP entry point regexes don't match) location ~* (\.php$|\.phtml$|\.htaccess$|\.git) {
deny all; }
# deny access to .htaccess files, if Apache's document root # concurs with nginx's one # location ~ /\.ht {
deny all; } }