O arquivo de configuração Nginx se parece com o seguinte:
Dentro do bloco http
server {
listen *:80 default_server;
server_name "";
# return 444;
root /var/www/default_server;
error_log /var/log/nginx/error.default_server.log debug;
access_log /var/log/nginx/access.default_server.log custom_made_access_log_1;
port_in_redirect on;
server_name_in_redirect on;
server_tokens on;
index index.html index.htm default.html default.htm index.php;
merge_slashes on;
location = /basic_status {
stub_status on;
allow 192.168.80.1;
deny all;
}
location = / {
}
location / {
try_files $uri $uri/ =404;
location ~* ^/phpmyadmin$ {
rewrite ^/(phpmyadmin)$ /$1/ last;
}
location ~* ^/(.+\.php)$ {
include fastcgi.conf;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors on;
fastcgi_pass unix:/run/php-fpm/www.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location ~* ^/(.+\.(png|swf|pdf|jpg|jpeg|gif|css|png|js|ico|html|htm|xml|txt|zip|rar|fla|mov|mp4))$ {
}
}
location /phpmyadmin/ {
alias /var/www/default_server/phpmyadmin/;
error_log /var/log/nginx/error.default_server.phpMyAdmin.log debug;
access_log /var/log/nginx/access.default_server.phpMyAdmin.log custom_made_access_log_1;
# try_files $uri $uri/ /phpmyadmin/index.php?$query_string;
location ~* ^/phpmyadmin/setup {
}
location ~* ^/phpmyadmin/(.+\.php)$ {
include fastcgi.conf;
fastcgi_split_path_info ^/phpmyadmin/(.+?\.php)(.*)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors on;
fastcgi_pass unix:/run/php-fpm/www.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location ~* ^/phpmyadmin/(.+\.(png|swf|pdf|jpg|jpeg|gif|css|png|js|ico|html|htm|xml|txt|zip|rar|fla|mov|mp4))$ {
#avoid processing of calls to unexisting static files
try_files $uri =404;
}
}
}
Eu tenho 2 casos como segue:
Caso 1:http://192.168.80.129/phpmyadmin/
caso 2:http://192.168.80.129/phpmyadmin
O caso 1 funciona bem. a localização
location /phpmyadmin/
funciona conforme o esperado.
o relé do problema no Caso 2, que está sem a barra final.
como você pode ver na configuração acima:
sob a diretiva do servidor, configurei o "root" da seguinte forma:
root /var/www/default_server;
e também, como você pode ver na configuração acima, configurei dentro do local /phpmyadmin/
location /phpmyadmin/
a seguir:
alias /var/www/default_server/phpmyadmin/;
Além disso, dentro do local do bloco ~* ^/phpmyadmin/(.+.php)$
location ~* ^/phpmyadmin/(.+\.php)$
Eu configurei o seguinte
fastcgi_split_path_info ^/phpmyadmin/(.+?\.php)(.*)$;
o que posso ver no log do DEBUG é o seguinte:
uma vez que eu navego parahttp://192.168.80.129/phpmyadmin então vejo no DEBUG LOG o seguinte
2020/12/12 15:40:10 [debug] 52078#0: *1 HTTP/1.1 404 Not Found
e a parte do arquivo de log completo:
2020/12/12 15:40:10 [debug] 52078#0: *1 test location: "/"
2020/12/12 15:40:10 [debug] 52078#0: *1 test location: "phpmyadmin/"
2020/12/12 15:40:10 [debug] 52078#0: *1 test location: "basic_status"
2020/12/12 15:40:10 [debug] 52078#0: *1 test location: ~ "^/phpmyadmin$"
2020/12/12 15:40:10 [debug] 52078#0: *1 using configuration "^/phpmyadmin$"
2020/12/12 15:40:10 [debug] 52078#0: *1 http cl:-1 max:1048576
2020/12/12 15:40:10 [debug] 52078#0: *1 rewrite phase: 3
2020/12/12 15:40:10 [debug] 52078#0: *1 http script regex: "^/(phpmyadmin)$"
2020/12/12 15:40:10 [notice] 52078#0: *1 "^/(phpmyadmin)$" matches "/phpmyadmin", client: 192.168.80.1, server: , request: "GET /phpmyadmin HTTP/1.1", host: "192.168.80.129"
2020/12/12 15:40:10 [debug] 52078#0: *1 http script copy: "/"
2020/12/12 15:40:10 [debug] 52078#0: *1 http script capture: "phpmyadmin"
2020/12/12 15:40:10 [debug] 52078#0: *1 http script copy: "/"
2020/12/12 15:40:10 [debug] 52078#0: *1 http script regex end
2020/12/12 15:40:10 [notice] 52078#0: *1 rewritten data: "/phpmyadmin/", args: "", client: 192.168.80.1, server: , request: "GET /phpmyadmin HTTP/1.1", host: "192.168.80.129"
2020/12/12 15:40:10 [debug] 52078#0: *1 post rewrite phase: 4
2020/12/12 15:40:10 [debug] 52078#0: *1 uri changes: 11
2020/12/12 15:40:10 [debug] 52078#0: *1 test location: "/"
2020/12/12 15:40:10 [debug] 52078#0: *1 test location: "phpmyadmin/"
2020/12/12 15:40:10 [debug] 52078#0: *1 test location: ~ "^/phpmyadmin/setup"
2020/12/12 15:40:10 [debug] 52078#0: *1 test location: ~ "^/phpmyadmin/(.+\.php)$"
2020/12/12 15:40:10 [debug] 52078#0: *1 test location: ~ "^/phpmyadmin/(.+\.(png|swf|pdf|jpg|jpeg|gif|css|png|js|ico|html|htm|xml|txt|zip|rar|fla|mov|mp4))$"
2020/12/12 15:40:10 [debug] 52078#0: *1 using configuration "/phpmyadmin/"
2020/12/12 15:40:10 [debug] 52078#0: *1 rewrite phase: 1
2020/12/12 15:40:10 [debug] 52078#0: *1 test location: "/"
2020/12/12 15:40:10 [debug] 52078#0: *1 test location: "phpmyadmin/"
2020/12/12 15:40:10 [debug] 52078#0: *1 test location: ~ "^/phpmyadmin/setup"
2020/12/12 15:40:10 [debug] 52078#0: *1 test location: ~ "^/phpmyadmin/(.+\.php)$"
2020/12/12 15:40:10 [debug] 52078#0: *1 using configuration "^/phpmyadmin/(.+\.php)$"
2020/12/12 15:40:10 [debug] 52078#0: *1 event timer del: 18: 707626498
2020/12/12 15:40:10 [debug] 52078#0: *1 http process request line
2020/12/12 15:40:10 [debug] 52078#0: *1 http request line: "GET /themes/pmahomme/jquery/jquery-ui.css HTTP/1.1"
2020/12/12 15:40:10 [debug] 52078#0: *1 http uri: "/themes/pmahomme/jquery/jquery-ui.css"
2020/12/12 15:40:10 [debug] 52078#0: *1 http args: ""
2020/12/12 15:40:10 [debug] 52078#0: *1 http exten: "css"
2020/12/12 15:40:10 [debug] 52078#0: *1 posix_memalign: 00005626A1D05AF0:4096 @16
2020/12/12 15:40:10 [debug] 52078#0: *1 http process request header line
2020/12/12 15:40:10 [debug] 52078#0: *1 http header: "Host: 192.168.80.129"
2020/12/12 15:40:10 [debug] 52078#0: *1 http header: "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:83.0) Gecko/20100101 Firefox/83.0"
2020/12/12 15:40:10 [debug] 52078#0: *1 http header: "Accept: text/css,*/*;q=0.1"
2020/12/12 15:40:10 [debug] 52078#0: *1 http header: "Accept-Language: en-US,en;q=0.5"
2020/12/12 15:40:10 [debug] 52078#0: *1 http header: "Accept-Encoding: gzip, deflate"
2020/12/12 15:40:10 [debug] 52078#0: *1 http header: "Connection: keep-alive"
2020/12/12 15:40:10 [debug] 52078#0: *1 http header done
2020/12/12 15:40:10 [debug] 52078#0: *1 generic phase: 0
2020/12/12 15:40:10 [debug] 52078#0: *1 rewrite phase: 1
2020/12/12 15:40:10 [debug] 52078#0: *1 test location: "/"
2020/12/12 15:40:10 [debug] 52078#0: *1 test location: "phpmyadmin/"
2020/12/12 15:40:10 [debug] 52078#0: *1 test location: ~ "^/phpmyadmin$"
2020/12/12 15:40:10 [debug] 52078#0: *1 test location: ~ "^/(.+\.php)$"
2020/12/12 15:40:10 [debug] 52078#0: *1 test location: ~ "^/(.+\.(png|swf|pdf|jpg|jpeg|gif|css|png|js|ico|html|htm|xml|txt|zip|rar|fla|mov|mp4))$"
2020/12/12 15:40:10 [debug] 52078#0: *1 using configuration "^/(.+\.(png|swf|pdf|jpg|jpeg|gif|css|png|js|ico|html|htm|xml|txt|zip|rar|fla|mov|mp4))$"
2020/12/12 15:40:10 [debug] 52078#0: *1 http cl:-1 max:1048576
2020/12/12 15:40:10 [debug] 52078#0: *1 rewrite phase: 3
2020/12/12 15:40:10 [debug] 52078#0: *1 post rewrite phase: 4
2020/12/12 15:40:10 [debug] 52078#0: *1 generic phase: 5
2020/12/12 15:40:10 [debug] 52078#0: *1 generic phase: 6
2020/12/12 15:40:10 [debug] 52078#0: *1 generic phase: 7
2020/12/12 15:40:10 [debug] 52078#0: *1 generic phase: 8
2020/12/12 15:40:10 [debug] 52078#0: *1 access phase: 9
2020/12/12 15:40:10 [debug] 52078#0: *1 access phase: 10
2020/12/12 15:40:10 [debug] 52078#0: *1 access phase: 11
2020/12/12 15:40:10 [debug] 52078#0: *1 post access phase: 12
2020/12/12 15:40:10 [debug] 52078#0: *1 generic phase: 13
2020/12/12 15:40:10 [debug] 52078#0: *1 generic phase: 14
2020/12/12 15:40:10 [debug] 52078#0: *1 content phase: 15
2020/12/12 15:40:10 [debug] 52078#0: *1 content phase: 16
2020/12/12 15:40:10 [debug] 52078#0: *1 content phase: 17
2020/12/12 15:40:10 [debug] 52078#0: *1 content phase: 18
2020/12/12 15:40:10 [debug] 52078#0: *1 content phase: 19
2020/12/12 15:40:10 [debug] 52078#0: *1 content phase: 20
2020/12/12 15:40:10 [debug] 52078#0: *1 http filename: "/var/www/default_server/themes/pmahomme/jquery/jquery-ui.css"
2020/12/12 15:40:10 [debug] 52078#0: *1 add cleanup: 00005626A1DA7AD8
2020/12/12 15:40:10 [error] 52078#0: *1 open() "/var/www/default_server/themes/pmahomme/jquery/jquery-ui.css" failed (2: No such file or directory), client: 192.168.80.1, server: , request: "GET /themes/pmahomme/jquery/jquery-ui.css HTTP/1.1", host: "192.168.80.129"
2020/12/12 15:40:10 [debug] 52078#0: *1 http finalize request: 404, "/themes/pmahomme/jquery/jquery-ui.css?" a:1, c:1
2020/12/12 15:40:10 [debug] 52078#0: *1 http special response: 404, "/themes/pmahomme/jquery/jquery-ui.css?"
2020/12/12 15:40:10 [debug] 52078#0: *1 http set discard body
2020/12/12 15:40:10 [debug] 52078#0: *1 xslt filter header
2020/12/12 15:40:10 [debug] 52078#0: *1 HTTP/1.1 404 Not Found
Server: nginx/1.18.0
Date: Sat, 12 Dec 2020 13:40:10 GMT
Content-Type: text/html
Content-Length: 153
Connection: keep-alive
e posso ver que a origem do problema começa na linha seguinte
2020/12/12 15:40:10 [debug] 52078#0: *1 http request line: "GET /themes/pmahomme/jquery/jquery-ui.css HTTP/1.1"
2020/12/12 15:40:10 [debug] 52078#0: *1 http uri: "/themes/pmahomme/jquery/jquery-ui.css"
como você pode ver o problema é:
"GET /themes/pmahomme/jquery/jquery-ui.css HTTP/1.1"
Por que a solicitação se tornou
/themes/pmahomme/jquery/jquery-ui.css
e não como
/phpmyadmin/themes/pmahomme/jquery/jquery-ui.css
então, supondo que esta seja a maneira que eu gostaria de implementar. o que devo fazer para superar o problema.
Quando o bloco de localização
location / {
try_files $uri $uri/ =404;
location ~* ^/phpmyadmin$ {
rewrite ^/(phpmyadmin)$ /$1/ last;
}
}
lidar com a solicitação, então a reescrita funciona bem, mas descobri que o sistema de arquivos está tentando localizar os arquivos usando a configuração de
root /var/www/default_server;
em vez de usar a configuração de alias
alias /var/www/default_server/phpmyadmin/;
que residem dentro do bloco de localização de
location /phpmyadmin/
Responder1
Se bem entendi, você só deseja usar o PHPMyAdmin em /phpmyadmin/
. Por que você simplesmente não entrega (em vez de entregar conteúdo em /phpmyadmin
) um redirecionamento de /phpmyadmin
para /phpmyadmin/
e pronto?
location /phpmyadmin
{
return 303 https://example.com/phpmyadmin/;
}
Não testado.
Responder2
Por último, o que fiz foi a seguinte abordagem:
location ~* ^/phpmyadmin$ {
return 301 http://$host:$server_port/phpmyadmin/;
}
location ~* ^/phpmyadmin/$ {
return 301 http://$host:$server_port/phpmyadmin/;
}
Com isso consegui redirecionar letras maiúsculas e minúsculas para uma URL específica