[英]My index.php is downloading as a file instead of executing when i run it
[英]web browser is downloading index.php from my web server instead of executing it
我正在設置一個可以運行 PHP 文件的 nginx Web 服務器,特別是對於 selfoss rss 查看器。 出於某種原因,當我訪問我的網站時,它會下載 index.php 文件而不是在服務器上執行它。 我在樹莓派 1B 上運行它。
是的,我確實重新啟動了 nginx 並清除了我的網絡瀏覽器緩存。 它沒有解決任何問題。
這是我的 PHP 版本:
$ php -v
PHP 7.4.30 (cli) (built: Jul 7 2022 15:51:43) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.30, Copyright (c), by Zend Technologies
這是我的nginx配置:
server {
server_name rss.getty.nz;
root /var/www/rss.getty;
access_log /var/www/rss.getty/rss.accesss.log;
error_log /var/www/rss.getty/rss.error.log;
index index.php;
location / {
try_files $uri /public/$uri /index.php$is_args$args =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf ;
include fastcgi_params;
fastcgi_pass unix:/run/php/php7.4-fpm.sock ;
}
location ~* \ (gif|jpg|png) {
expires 30d;
}
location ~ ^/(favicons|thumbnails)/.*$ {
try_files $uri /data/$uri;
}
location ~* ^/(data\/logs|data\/sqlite|config\.ini|\.ht) {
deny all;
}
listen [::]:443 ssl; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/rss.getty.nz/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/rss.getty.nz/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
access_log /var/www/rss.getty/rss.accesss.log;
error_log /var/www/rss.getty/rss.error.log;
}
server {
if ($host = rss.getty.nz) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
listen [::]:80;
server_name rss.getty.nz;
return 404; # managed by Certbot
}
以下是 /etc/nginx/snippets/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;
感謝評論中的理查德史密斯,我有答案了。 這是本節中的 =404:
location / {
try_files $uri /public/$uri /index.php$is_args$args =404;
}
刪除它會阻止 Web 瀏覽器下載。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.