server_name
如果这正是您正在使用的,那么您的 nginx 配置看起来不错,那么我不知道到底出了什么问题,但让我整理一下您的配置,可能会有所帮助
对于重定向,我更喜欢使用单独的服务器进行重定向,而不是使用 if 条件
server {
listen 80;
server_name www.example.com;
return 301 example.com$request_uri;
}
无需重新声明根和索引。在服务器块级别指定一次就足够了。
server {
listen 80;
server_name example.com;
root /home/sushi/www/example/;
access_log /home/sushi/www/example/logs/access.log;
error_log /home/sushi/www/example/logs/error.log;
index index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
}
由于您manifest.appcache
的确切位置,$uri
因此您无需明确提及它,问题是 nginx 与服务器块不匹配。
另一个随机的想法是,也许 nginx 不知道服务器存在,因为您在创建服务器后没有重新启动 nginx ..您尝试过吗?
编辑:里面的块nginx.conf
应该移到example.conf
文件
server {
listen 80;
server_name example.com;
root /home/sushi/www/example/;
access_log /home/sushi/www/example/logs/access.log;
error_log /home/sushi/www/example/logs/error.log;
index index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
location ~* \.(?:manifest|appcache|html?|xml|json)$ {
expires -1;
access_log logs/static.log;
}
}