尝试通过端口80上的IP访问我的服务器时遇到问题。
如果我去IP我得到nginx 404错误页面。
这是我的默认configuration看起来像:
# You may add here your # server { # ... # } # statements for each of your virtual hosts to this file server { listen 80; ## listen for ipv4; this line is default and implied #listen [::]:80 default ipv6only=on; ## listen for ipv6 # Document root root /var/www/default; index index.html index.htm; # Make site accessible from http://localhost/ server_name localhost; location / { # First attempt to serve request as file, then # as directory, then fall back to index.html try_files $uri $uri/ /index.html; # Uncomment to enable naxsi on this location # include /etc/nginx/naxsi.rules } location /doc/ { alias /usr/share/doc/; autoindex on; allow 127.0.0.1; deny all; } # Only for nginx-naxsi : process denied requests #location /RequestDenied { # For example, return an error code #return 418; #} #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # #error_page 500 502 503 504 /50x.html; #location = /50x.html { # root /usr/share/nginx/www; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # fastcgi_split_path_info ^(.+\.php)(/.+)$; # # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini # # # With php5-cgi alone: # fastcgi_pass 127.0.0.1:9000; # # With php5-fpm: # fastcgi_pass unix:/var/run/php5-fpm.sock; # fastcgi_index index.php; # include fastcgi_params; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} }
在/var/www/default里面有一个名为index.html的文件。 现在到怪异的部分。 如果我把监听端口改为8888 nginx会正确地提供index.html。 我只有3个网站,其他的是虚拟主机,所以他们没有听指令。 我已经将/var/www/default文件夹设置为chmod 777 ,但仍然在端口80上返回404 。
编辑:我检查了nginx的错误日志,这是说: 2014/04/08 09:30:21 [error] 3349#0: *1 "/etc/nginx/html/index.html" is not found
然后问题是,这个configuration在哪里说/etc/nginx/html/index.html是默认的根?
您的listen指令中没有default_server选项。 因此,该请求与您的nginxconfiguration中的某个其他虚拟主机相匹配。
所以,试试这个作为你的听线:
listen 80 default_server;
那么你可能必须从其他虚拟主机中删除default_server ,如果他们有这个定义。
另一件事可能是,你是否使用127.0.0.1或localhost访问服务器? server_name localhost表示仅在URL中使用localhost时才使用虚拟主机。