Я пытаюсь установить хорошие URL для nginx. Я хочу переписать, например, example.com/account.php в example.com/dashboard с
location = /dashboard {
rewrite ^dashboard/?$ /acc0unt.php last;
}
Но это не работает. Nginx загружает файл вместо. Полная конфигурация nginx:
server {
server_name www.example.com;
return 301 $scheme://example.com$request_uri; # port 80 default
listen 443 ssl http2; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server { # port 80 default
access_log /var/log/nginx/example.com.access.log;
error_log /var/log/nginx/example.com.error.log;
root /var/www/example.com/; # default directory where the files will be stored and served from
index index.php index.html index.htm; # index defined to be served under directory
server_name example.com; # name of the virtual host or domain
location / {
# URLs to attempt, including pretty ones.
try_files $uri $uri/ /index.php?$args;
}
error_page 404 500 502 503 504 /404.php;
location = /404.php {
root /var/www/example.com/;
}
# Remove trailing slash to please routing system.
if (!-d $request_filename) {
rewrite ^/(.+)/$ /$1 permanent;
}
# Serve PHP scripts to FastCGI server our php-fpm server listening on 127.0.0.1:9000
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
}
include common/locations.conf;
# redirects start
rewrite ^/signup-([0-9]+).php$ https://example.com/recruit.php?ref=$1 permanent;
rewrite ^/([0-9]+)-([a-z]+)-([0-9]+).php$ https://example.com/idevads.php?id=$1&ad=$3 permanent;
rewrite ^/([0-9]+)-([a-z]+)-([0-9]+)-([0-9]+).php$ https://example.com/idevads.php?id=$1&ad=$3&page=$4 permanent;
rewrite ^/([0-9]+).php$ https://example.com/promo.php?id=$1 permanent;
rewrite ^/([0-9]+)-([0-9]+).php$ https://example.com/promo.php?id=$1&page=$2 permanent;
rewrite ^/([0-9]+)-([0-9]+)-([0-9]+).php$ https://example.com/promo.php?id=$1&page=$2&set=$3 permanent;
rewrite ^/([0-9]+)-([0-9]+)-([0-9]+)-([0-9]+).php$ https://example.com/promo.php?id=$1&page=$2&set=$3&link=$4 permanent;
rewrite ^/([0-9]+)-([0-9]+)-([0-9]+)-([0-9]+)-([a-zA-Z]+).php$ https://example.com/promo.php?id=$1&page=$2&set=$3&link=$4&keyword=$5 permanent;
rewrite ^/([0-9]+)-([0-9]+)-([0-9]+)-([0-9]+)-([a-zA-Z]+)-([0-9]+).php$ https://example.com/promo.php?id=$1&page=$2&set=$3&link=$4&keyword=$5&custom=$6 permanent;
rewrite ^/([0-9]+)-([0-9]+)-([0-9]+)-([0-9]+)-([a-zA-Z]+)-([0-9]+)-([0-9]+).php$ https://example.com/promo.php?id=$1&page=$2&set=$3&link=$4&keyword=$5&custom=$6&url=$7 permanent;
# redirects end
#rewrites start
//rewrite php files to dir names here
#rewrites end
listen 443 ssl http2; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = example.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 0.0.0.0:80;
server_name example.com;
return 404; # managed by Certbot
}server {
if ($host = www.example.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
server_name www.example.com;
listen 0.0.0.0:80;
return 404; # managed by Certbot
}
Фрагмент fastcgi-php.conf:
# regex to split $uri to $fastcgi_script_name and $fastcgi_path
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# Check that the PHP script exists before passing it
try_files $fastcgi_script_name =404;
# Bypass the fact that try_files resets $fastcgi_path_info
# see: http://trac.nginx.org/nginx/ticket/321
set $path_info $fastcgi_path_info;
fastcgi_param PATH_INFO $path_info;
fastcgi_index index.php;
include fastcgi.conf;
Есть идеи как решить это? Я хочу служить / приборной панели и запустить acc0unt.php, например. Я прочитал некоторые посты здесь, и ни один действительно не помог.
Задача ещё не решена.
Других решений пока нет …