Nginx alternate index not working
Trying to force login.php or / login to become an index page when navigating to a subdomain, but all I get is a blank page.
The configuration is below:
server {
listen 80;
server_name *.domain.org;
root /var/www/html/domain.org/public;
index login login.php index.php index.html index.htm;
location ~* \.(css|js|png|woff2|woff|ttf|jpg|jpeg|gif|ico)$ {}
location = / {
index login.php;
}
location / {
try_files $uri $uri.php login;
rewrite ^(.*)$ $uri.php;
}
error_page 404 404;
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
+3
source to share
1 answer
This works for me:
server {
listen 80;
server_name *.domain.org;
root /var/www/html/domain.org/public;
index index.php index.html index.htm;
location ~* \.(css|js|png|woff2|woff|ttf|jpg|jpeg|gif|ico)$ {}
location / {
index login.php;
}
error_page 404 404;
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
If you're still not working, try adding a log to the server directive and see what's wrong:
error_log /var/www/html/domain.org/public/nginx-error.log;
access_log /var/www/html/domain.org/public/nginx-access.log;
0
source to share