【发布时间】:2021-10-12 15:31:00
【问题描述】:
我正在使用nginx,而我的网络服务器htdocs 文件夹包含几个*.html 文件。即使请求不包含 *.html 扩展名,我也想为他们提供服务。
我在这里找到的大多数答案都应用了rewrite,它将在浏览器地址栏中可见。我怎样才能实现相同但“静默”?
示例: www.example.com/foo => www.example.com/foo.html
如果我没记错的话,/opt/bitnami/apps/wordpress/conf/nginx-app.conf 是应用这些更改的最佳位置。
index index.php index.html index.htm;
if ($request_uri !~ "^/phpmyadmin.*$")
{
set $test A;
}
if ($request_uri !~ "^/bitnami.*$")
{
set $test "${test}B";
}
if (!-e $request_filename)
{
set $test "${test}C";
}
if ($test = ABC) {
rewrite ^/(.+)$ /index.php?q=$1 last;
}
# Deny access to any files with a .php extension in the uploads directory
location ~* /(?:uploads|files)/.*\.php$ {
deny all;
}
# Disable logging for not found files and access log for the favicon and robots
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
include "/opt/bitnami/apps/bitnami/banner/conf/banner-substitutions.conf";
include "/opt/bitnami/apps/bitnami/banner/conf/banner.conf";
# Deny all attempts to access hidden files such as .htaccess or .htpasswd.
location ~ /\. {
deny all;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_read_timeout 300;
fastcgi_pass unix:/opt/bitnami/php/var/run/www.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $request_filename;
include fastcgi_params;
}
【问题讨论】:
标签: nginx nginx-config nginx-location