[英]WordPress doesn't respect nginx headers
我在VPS上托管一些網站,一些“靜態”網站和一些動態(WordPress)網站。 靜態網站(靜態PHP頁面)“尊重”我在nginx conf,http部分中設置的標題。 例:
add_header Strict-Transport-Security "max-age=31536000; includeSubdomains;";
add_header X-Cache $upstream_cache_status;
標題:
HTTP/1.1 200 OK
Server: nginx
Date: Tue, 16 Sep 2014 17:09:04 GMT
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Vary: Accept-Encoding
X-Frame-Options: SAMEORIGIN
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
X-Cache: HIT
Strict-Transport-Security: max-age=31536000; includeSubdomains;
WordPress網站反而沒有我設置的這些標頭:
HTTP/1.1 200 OK
Server: nginx
Date: Tue, 16 Sep 2014 17:08:25 GMT
Content-Type: text/html; charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
Vary: Accept-Encoding
X-Pingback: http://website.com/xmlrpc.php
Link: <http://wp.me/P4zIfv-2>; rel=shortlink
X-UA-Compatible: IE=Edge,chrome=1
這兩個網站具有相同的虛擬主機配置! 當然,liste,server_name,索引等。然后是位置:
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
fastcgi_cache website.com;
fastcgi_cache_valid 200 20m;
fastcgi_cache_bypass $no_cache;
fastcgi_no_cache $no_cache;
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include /etc/nginx/fastcgi.conf;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
WP為什么會發生這種情況?
請參閱: nginx add_header不起作用
“第二個問題是我所在的位置/ {}塊實際上是將nginx發送到另一個位置〜*(.php)$塊(因為它將通過index.php重定向所有請求,這實際上使nginx對此進行處理因此,我在第一個location指令中使用的add_header指令是無用的,並且在我將所需的所有指令放入php location指令后,它開始工作。”
另請參閱: https : //gist.github.com/adityamenon/6753574
因此,將它們放在您的位置塊內
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.