我在我的VPS上托管了一些网站,其中一些是#34;静态"和一些动态(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
这两个网站有相同的vhost配置!当然是liste,server_name,index ecc ..然后是位置:
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为什么会这样?
答案 0 :(得分:1)
请参阅:nginx add_header not working
&#34;第二个问题是我所使用的位置/ {}块实际上是将nginx发送到另一个位置〜*(.php)$ block(因为它会通过index.php重新发送所有请求,并且这实际上使nginx处理这个php块)。所以,我在第一个位置指令中的add_header指令是无用的,并且在我将所需的所有指令放入php位置指令之后它开始工作。&#34;
另请参阅:https://gist.github.com/adityamenon/6753574
所以把它们放在你的位置栏中