2017-01-31 115 views
0

我想配置Nginx服務器來處理與所有其他請求不同的請求/ awstats。我也爲/ fpm-狀態這麼做了。但是,這個特定的位置似乎不起作用。我嘗試了所有位置匹配的排列。確切的問題是位置「/ awstats」也被重寫到php url。有人可以在下面的配置中指出我的錯誤嗎?Nginx的位置塊不起作用

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

您的位置聲明似乎是混亂前綴位置和正則表達式位置語法:

location ^~ ^/awstats 

^~改性劑與前綴位置更改其評估順序,但在這裏您已指定了一個定期e表達式參數。

二者必選其一:

location ^~ /awstats 

或:

location ~ ^/awstats 

詳見this document

+0

現在都試過了。可悲的是要麼沒有工作。我甚至嘗試過精確匹配。這也是行不通的。 – user3295878