我在Ubuntu 16.04服务器上运行nginx 1.4.6。我的内容由文件夹/var/www/html/
,index.html
和test.html
中的两个文件组成。所有文件均为755,属于用户www-data
。我的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 / {
}
}
当我浏览http://example.com/(不是真正的主机名(时,我会看到 index.html
(yay(的内容。当我浏览到http://example.com/test.html时,我会得到http 404.我尝试使用curl和任何浏览器时就得到了。
本网站上的许多其他问题(以及在服务器型上(似乎表明了与重写规则一起使用静态内容或与其他服务的反向代理的问题。我只想能够为可以想象的最简单的静态网站提供服务。
access.log和error.log甚至都不显示任何请求正在通过。日志文件都是由用户www-data拥有的,并允许写入访问。
在您当前配置中访问example.com
中的控件将为
到达location /
块,您没有提及的入口点,因此
将配置更改为
server {
listen 80;
root /var/www/html/;
index index.html index.htm;
server_name example.com;
}
或
server {
listen 80;
index index.html index.htm;
server_name example.com;
location /{
# you can use alias instead
root /var/www/html/;
}
}