I recently moved my server from apache to nginx, when using apache i had a working site using the Laravel framework.
For some reason no pages other than the base index page just return a 404 error. I am sure it has something to do with my nginx config. My currently config is shown below.
server {
listen 80;
server_name munkeemagic.munkeejuice.co.uk;
root /var/www/html/munkeemagic/mtg-webby/mtg/public;
index index.php index.html;
location / {
try_files $uri $uri/ /index.php?$is_args$args;
}
location ~* \.php$ {
try_files $uri /index.php =404;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
I have checked to make sure that all the file permissions are set for user www-data which is the user nginx is using. I have even tried changing
location / {
try_files $uri $uri/ /index.php?$is_args$args;
}
to
location / {
try_files $uri $uri/ index.php?$query_string;
}
but that has not had any impact and i still see the same issue.
So basically with this config if i navigate to http://munkeemagic.munkeejuice.co.uk then the page displays
if i go to http://munkeemagic.munkeejuice.co.uk/login i get a 404 error.
Does anyone have any idea what i may be doing wrong ?
After following user3647971's advice i have modified the config as follows :
server {
listen 80;
server_name munkeemagic.munkeejuice.co.uk;
root /var/www/html/munkeemagic/mtg-webby/mtg/public;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
index index.php index.html;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
error_page 404 /index.php;
location ~* \.php$ {
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
}
I have restarted nginx to take the changes and have also cleared the routes cache, but unfortunately i still have the same problem.
Ok figured out the problem, tbh i was a bit stupid. My default configuration was overriding my website specific config. I unlinked the default config restarted nginx and everything started to work correctly.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.