我正在尝试配置nginx服务器以处理与/ awstats的请求不同于所有其他请求。我也是这样做的/ fpm-status。但是,这个特定的位置似乎不起作用。我已经尝试了所有位置匹配的排列。确切的问题是位置" / awstats"也被重写为php网址。有人可以在下面的配置中指出我的错误吗?
server {
listen 80;
listen 443 ssl;
ssl on;
ssl_certificate /etc/ssl/bundle.crt;
ssl_certificate_key /etc/ssl/domain.key;
server_name domain.tld;
root /var/www/html/project/;
index index.php index.html index.htm;
location ^~ ^/awstats {
root /var/www/awstats/domain.tld/;
index awstats.domain.tld.html;
}
location ~ ^/awstats-icon/ {
alias /var/www/awstats/icon/;
}
location ~* \.tpl|\.ini|\.log|(?<!robots)\.txt$ {
deny all;
return 404;
}
location ~ ^/fpm_status {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_pass php-fpm;
allow 127.0.0.1;
allow 43.252.193.74;
allow 172.31.3.18;
deny all;
}
location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
expires 365d;
}
rewrite ^/sitemap.xml$ /index.php?route=feed/google_sitemap last;
rewrite ^/googlebase.xml$ /index.php?route=feed/google_base last;
rewrite ^/system/download/(.*) /index.php?route=error/not_found last;
if (!-f $request_filename){
set $rule_3 1$rule_3;
}
if (!-d $request_filename){
set $rule_3 2$rule_3;
}
if ($uri !~ ".*.(ico|gif|jpg|jpeg|png|js|css)"){
set $rule_3 3$rule_3;
}
rewrite ^/api/((?!apidoc).*) /index.php?route=api/$1 last;
rewrite ^/admin_api/((?!adminapidoc).*) /admin/index.php?route=admin_api/$1 last;
rewrite ^/((?!admin|favicon|awstats|fpm_status|robots)(.*)) /index.php?_route_=$1 last;
location / {
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
access_log /var/log/nginx/domain.tld.access.log timed_combined;
}
答案 0 :(得分:0)
您的位置声明似乎让前缀位置和正则表达式位置语法混淆:
location ^~ ^/awstats
^~
修饰符与前缀位置一起使用以更改其评估顺序,但此处您已指定正则表达式参数。
使用:
location ^~ /awstats
或:
location ~ ^/awstats
有关详细信息,请参阅this document。