Nginx静态内容404在除索引之外的每个文件上都有错误
我的nginx 1.4.6运行在ubuntu 16.04服务器上。我的内容由文件夹Nginx静态内容404在除索引之外的每个文件上都有错误,nginx,ubuntu-16.04,Nginx,Ubuntu 16.04,我的nginx 1.4.6运行在ubuntu 16.04服务器上。我的内容由文件夹/var/www/html/、index.html和test.html中的两个文件组成。所有文件都是chmod'ed到755的,属于用户www-data。My nginx.conf: user www-data; worker_processes auto; pid /run/nginx.pid; events { worker_connections 768;
/var/www/html/
、index.html
和test.html
中的两个文件组成。所有文件都是chmod'ed到755的,属于用户www-data
。My nginx.conf:
user www-data;
worker_processes auto;
pid /run/nginx.pid;
events {
worker_connections 768;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
gzip on;
gzip_disable "msie6";
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
我在/etc/nginx/sites enabled/中的配置文件:
server {
listen 80;
root /var/www/html/;
index index.html index.htm;
server_name example.com;
location / {
}
}
当我浏览到(不是真正的主机名)时,我会看到index.html
(耶)的内容。当我浏览到我得到的HTTP 404。我在尝试使用curl和任何浏览器时都会遇到这种情况
该站点(以及serverfault)上的许多其他问题似乎表明,使用重写规则或反向代理到其他服务的组合服务静态内容时存在问题。我只是想能够服务于最简单的静态网站可以想象
access.log和error.log甚至都没有显示任何请求正在通过。日志文件归用户www数据所有,并允许用户对其进行写访问。在当前配置中,访问
example.com
时,控件将为进入
location/
block在那里您没有提到入口点,因此将配置更改为
server {
listen 80;
root /var/www/html/;
index index.html index.htm;
server_name example.com;
}
或
您发布的内容很有效,但据我所知,与这里的Nginx文档直接矛盾:在“根在位置块内部”一节中,被认为是“坏的”。Nginx指定的建议是我采用的,这显然是不正确的。诚然,我使用的是一个旧版本的Nginx,但是其他人发现了这一点并试图直接基于文档构建一个简单的示例:不要这样做。实际上,这似乎仍然不起作用。我现在间歇性地得到404,有时我得到正确的页面,有时我得到404。@mephicide您可以使用alias代替。。。这意味着
/
表示html
文件夹
server {
listen 80;
index index.html index.htm;
server_name example.com;
location /{
# you can use alias instead
root /var/www/html/;
}
}