我在 Nginx 上的 /files/ 子文件夹中安装了一个 php 脚本,但是当我访问该页面时,它不起作用。只是显示 404 未找到。
我已在配置中添加此功能,但是不起作用。
location ^~ /files {
if (!-e $request_filename) { rewrite ^/(.*) /files/index.php?_page_url=$1 last; }
location ~ \.php$ {
if (!-e $request_filename) { rewrite ^/(.*) /files/index.php?_page_url=$1 last; }
fastcgi_pass unix:/run/php/php8.0-fpm-example.com.sock;
index index.php;
include /etc/nginx/fastcgi_params;
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $request_filename;
}
location /files/files/ {
internal;
}
# these locations would be hidden by .htaccess normally
location /files/logs/ {
deny all;
}
}
这是我的完整 nginx 配置,谢谢:
#=========================================================================#
# Default Web Domain Template #
# DO NOT MODIFY THIS FILE! CHANGES WILL BE LOST WHEN REBUILDING DOMAINS #
# https://docs.hestiacp.com/admin_docs/web.html#how-do-web-templates-work #
#=========================================================================#
server
{
listen myip:443 ssl http2;
server_name example.com;
root /home/smart/web/example.com/public_html;
index index.php index.html index.htm;
access_log /var/log/nginx/domains/example.com.log combined;
access_log /var/log/nginx/domains/example.com.bytes bytes;
error_log /var/log/nginx/domains/example.com.error.log error;
client_max_body_size 5G;
ssl_certificate /home/smart/conf/web/example.com/ssl/example.com.pem;
ssl_certificate_key /home/smart/conf/web/example.com/ssl/example.com.key;
ssl_stapling on;
ssl_stapling_verify on;
include /home/smart/conf/web/example.com/nginx.hsts.conf*;
location /
{
location ~* ^.+\.(jpeg|jpg|png|webp|gif|bmp|ico|svg|css|js)$
{
expires max;
fastcgi_hide_header "Set-Cookie";
}
location ~ [^/]\.php(/|$)
{
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
if (!-f $document_root$fastcgi_script_name)
{
return 404;
}
fastcgi_pass unix:/run/php/php8.0-fpm-example.com.sock;
fastcgi_index index.php;
include /etc/nginx/fastcgi_params;
include /home/smart/conf/web/example.com/nginx.fastcgi_cache.conf*;
}
}
location ^~ /files {
if (!-e $request_filename) { rewrite ^/(.*) /files/index.php?_page_url=$1 last; }
location ~ \.php$ {
if (!-e $request_filename) { rewrite ^/(.*) /files/index.php?_page_url=$1 last; }
fastcgi_pass unix:/run/php/php8.0-fpm-example.com.sock;
index
index.php;
include /etc/nginx/fastcgi_params;
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $request_filename;
}
location /files/files/ {
internal;
}
# these locations would be hidden by .htaccess normally
location /files/logs/ {
deny all;
}
}
location /error/
{
alias /home/smart/web/example.com/document_errors/;
}
location ~ /\.(?!well-known\/)
{
deny all;
return 404;
}
location /vstats/
{
alias /home/smart/web/example.com/stats/;
include /home/smart/web/example.com/stats/auth.conf*;
}
include /etc/nginx/conf.d/phpmyadmin.inc*;
include /etc/nginx/conf.d/phppgadmin.inc*;
include /home/smart/conf/web/example.com/nginx.conf_*;
}