嘗試在 Nginx 上安裝 phpMyAdmin。仔細閱讀所有教程,但是當我訪問我的網站時,my_IP/phpmyadmin我還是得到了 404 Not Found。當我通過輸入我的 IP 地址加載我的網站時,我得到了我的網站。但是在遵循本教程而不是顯示我的網站之后,我的瀏覽器會下載檔案“下載”。我從教程中洗掉了該代碼段,重新啟動了 Nginx,但瀏覽器仍然下載“下載”檔案而不是指向我的網站。當我輸入時,my_IP/phpmyadmin我仍然得到 404 Not Found。如何取回我的設定并在我的 Nginx 服務器上運行 phpMyAdmin?這是/etc/nginx/sites-available/default設定:
server {
listen 80 default_server;
listen [::]:80 default_server;
# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;
server_name _;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
# pass PHP scripts to FastCGI server
#
location ~ \.php$ {
include snippets/fastcgi-php.conf;
#
# # With php-fpm (or other unix sockets):
fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
# # With php-cgi (or other tcp sockets):
# fastcgi_pass 127.0.0.1:9000;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
location /phpmyadmin {
root /usr/share/;
index index.php index.html index.htm;
location ~ ^/phpmyadmin/(. \.php)$ {
try_files $uri =404;
root /usr/share/;
fastcgi_pass unix:/run/php/php8.1-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
location ~* ^/phpmyadmin/(. \.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
root /usr/share/;
}
}
}
UPD:
更新了我的PHP8.1,取消注釋了一些重要的代碼片段,并添加了該教程location /phpmyadmin中的代碼片段。看起來頁面加載正確,但 my_IP/phpmyadmin 仍然加載 404 Not Found。
uj5u.com熱心網友回復:
終于自己弄明白了。實際上在目錄中/etc/nginx/sites-available/我已經有兩個檔案,default并且my_website.com. 我放入的那段代碼default。但是現在我將此代碼移到my_website.com檔案中并且它起作用了:
location /phpmyadmin {
root /usr/share/;
index index.php index.html index.htm;
location ~ ^/phpmyadmin/(. \.php)$ {
try_files $uri =404;
root /usr/share/;
fastcgi_pass unix:/run/php/php8.1-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
location ~* ^/phpmyadmin/(. \.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
root /usr/share/;
}
}
感謝您的關注!
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/514454.html
