Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 仅提供欢迎索引页的nginx_Html_Http_Nginx_Amazon Ec2 - Fatal编程技术网

Html 仅提供欢迎索引页的nginx

Html 仅提供欢迎索引页的nginx,html,http,nginx,amazon-ec2,Html,Http,Nginx,Amazon Ec2,我正在EC2服务器上运行nginx 为了解决这个问题,我创建了一个单独的目录usr/loca/nginx/html/test,并将index.html文件的副本放在那里。我从usr/loca/nginx/html中删除了原始index.html文件 这是我的相关代码 nginx.conf.default worker_processes 1; events { worker_connections 1024; } http { include mime.types;

我正在EC2服务器上运行nginx

为了解决这个问题,我创建了一个单独的目录usr/loca/nginx/html/test,并将index.html文件的副本放在那里。我从usr/loca/nginx/html中删除了原始index.html文件

这是我的相关代码

nginx.conf.default

worker_processes  1;

events {
worker_connections  1024;
}

http {
    include       mime.types;
    include       usr/local/nginx/conf/*.conf
    default_type  application/octet-stream;

    sendfile        on;
    keepalive_timeout  65;
   server {
        listen       80;
        server_name  localhost;


        location / {
            root   html/test;
            index  index.html index.htm;
        }
  }
我尝试通过http://‘public ip address’/index.html访问该站点,得到的只是默认的nginx启动页面;即使我删除了这个文件,即使我将原始index.html文件中的文本更改为其他内容


我尝试重新加载nginx并清除缓存等…

我认为您的root指令没有指向正确的位置。您的root指令是相对的,即相对于当前文件夹。这是一件非常糟糕的事情。始终执行根相对指令。我会做类似的事情

/home/user/www/localhost

您可以选择一个您喜欢的目录,但要使其与根目录相对。注意前面的斜杠。如果欢迎页面工作正常,那么NGINX工作正常,错误通常在于错误的root指令。您还可以进行以下改进

  • 首先,从服务器块中获取根。将根目录放入服务器块是错误的。

  • 为什么您的Nginx配置文件名为Nginx.conf.default?它应该被称为nginx.conf(这也可能导致问题的出现。查看是否有一个名为nginx.conf的文件,并对其进行更改

  • 为什么要在nginx.conf中声明服务器?最好在文件夹中声明它,如

    可用站点/本地主机 可用站点/某些站点 ... 然后创建指向已启用站点的符号链接。这不是必需的,但这是一种良好的做法