NGINX不遵循alias指令
我正试图让nginx服务器上的一些静态文件。我输入了我认为应该是正确的指令来别名url,但nginx拒绝为页面提供服务器。我的server.conf如下所示:NGINX不遵循alias指令,nginx,Nginx,我正试图让nginx服务器上的一些静态文件。我输入了我认为应该是正确的指令来别名url,但nginx拒绝为页面提供服务器。我的server.conf如下所示: server { listen 80 default_server; listen [::]:80 default_server ipv6only=on; root /usr/share/nginx/html; index index.html index.htm ind
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/html;
index index.html index.htm index.php;
# Make site accessible from server.fqdn.suffix
server_name server.fqdn.suffix;
location /static/ {
autoindex on;
alias /usr/share/nginx/html/poindexter/inspire/static/;
}
# Include the basic h5bp config set
include /etc/nginx/h5bp/basic.conf;
}
我假设这将重定向到/usr/share/nginx/html/poindexter/inspire/static/
目录。对于自动索引来说,它似乎是有效的。但是当你点击一个文件时,它会产生一个404错误。我走了一步,果然,这不是为了纪念化名
[pid 2542] <... epoll_wait resumed> {{EPOLLIN, {u32=1822502928, u64=139901792235536}}}, 512, 4294967295) = 1
[pid 2542] accept4(10, {sa_family=AF_INET, sin_port=htons(37845), sin_addr=inet_addr("198.55.232.86")}, [16], SOCK_NONBLOCK) = 24
[pid 2542] epoll_ctl(21, EPOLL_CTL_ADD, 24, {EPOLLIN|EPOLLET, {u32=1822503697, u64=139901792236305}}) = 0
[pid 2542] epoll_wait(21, {{EPOLLIN, {u32=1822503697, u64=139901792236305}}}, 512, 10000) = 1
[pid 2542] recvfrom(24, "GET /static/css/bootstrap.min.cs"..., 1024, 0, NULL, NULL) = 772
[pid 2542] open("/usr/share/nginx/html/static/css/bootstrap.min.css", O_RDONLY|O_NONBLOCK) = -1 ENOENT (No such file or directory)
[pid 2542] write(8, "2014/03/05 21:59:23 [error] 2542"..., 328) = 328
[pid 2542] writev(24, [{"HTTP/1.1 404 Not Found\r\nServer: "..., 172}, {"<html>\r\n<head><title>404 Not Fou"..., 116}, {"<hr><center>nginx</center>\r\n</bo"..., 46}], 3) = 334
[pid 2542] setsockopt(24, SOL_TCP, TCP_NODELAY, [1], 4) = 0
[pid 2542] recvfrom(24, 0x14e9240, 1024, 0, 0, 0) = -1 EAGAIN (Resource temporarily unavailable
[pid 2542]{{EPOLLIN,{u32=1822502928,u64=139901792235536}},512,4294967295}=1
[pid 2542]accept4(10,{sa_family=AF_INET,sin_port=htons(37845),sin_addr=INET_addr(“198.55.232.86”)}[16],SOCK_NONBLOCK)=24
[pid 2542]epoll_ctl(21,epoll_ctl_ADD,24,{EPOLLIN|EPOLLET,{u32=1822503697,u64=139901792236305}})=0
[pid 2542]epoll_wait(21,{{EPOLLIN,{u32=1822503697,u64=139901792236305}}},512,10000)=1
[pid 2542]recvfrom(24,“GET/static/css/bootstrap.min.cs”…,1024,0,NULL,NULL)=772
[pid 2542]打开(“/usr/share/nginx/html/static/css/bootstrap.min.css”,O|RDONLY | O|NONBLOCK)=-1 enoint(没有这样的文件或目录)
[pid 2542]写入(8,“2014/03/05 21:59:23[错误]2542”…,328)=328
[pid 2542]writev(24,[{”HTTP/1.1 404未找到\r\n服务器:“…,172},{”\r\n404 Not Fou“…,116},{”
nginx\r\n我看到了几种解决方法
1.
只需将符号链接从/usr/share/nginx/html/static/
添加到/usr/share/nginx/html/poindexter/inspire/static/
并删除alias
指令。这有点像文件系统级别的别名
location /static/ {
autoindex on;
}
2.
删除location~*\.(?:css | js)${
块
3.
使用重写(此解决方案使用根目录中的静态目录)
basic.conf
?它是在安装过程中创建的,我没有删除它。它是指向#基本h5bp规则包括h5bp/directive only/x-ua-compatible.conf;包括h5bp/location/expires.conf;包括h5bp/location/cross-domain-fonts.conf;包括h5bp/location/protect system files.conf;它仍然是一个包含列表s、 我确信这些包含中有一些关于css文件的规则。你是对的。我给项目中的另一个程序员发了电子邮件,看起来它来自html5样板。其中有一条关于js/css的规则。location~*\(?:css | js)${expires 1y;access\u log off;add\u header Cache Control“public”}我不确定这其中哪一个正在扼杀js/css。你知道吗?
location ^~ /static/ {
autoindex on;
rewrite ^(.+)$ /poindexter/inspire$1;
}