所以,首先,是的,我一直在尋找解決方案,但我找不到。我知道問題出在我的重寫程式碼上,但我不知道如何修復它。我在 debian 9.5 上使用 nginx 和 php-fpm。
php 載入得很好,但 .html 不再工作。
server {
# SSL configuration
#
listen 443 ssl default_server;
listen [::]:443 ssl default_server;
root /var/www/example.com;
# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;
server_name example.com;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri.php;
rewrite ^(.*)$ $uri.php;
}
location /media {
autoindex on;
autoindex_exact_size off;
}
# 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/php7.0-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;
}
}
感謝收聽。我期待收到回音。
編輯:只是為了澄清,我的目的是讓 python 檔案不要在 url 中顯示 .php,而是讓 html 檔案正常載入。
答案1
本節
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri.php;
rewrite ^(.*)$ $uri.php;
}
看起來像是罪魁禍首。該rewrite
指令只是捕獲所有 URI 並將它們重寫到.php
檔案中。
根據評論編輯
基於類似的問題這裡,我認為你需要的是這樣的:
location / {
try_files $uri $uri/ @rules;
}
location @rules {
rewrite ^(.*)$ $1.php last;
}