NGNIX 服务器块不起作用

NGNIX 服务器块不起作用

我在 VPS ip 上有 4 个网站104.207.148.242。我已经成功安装 NGNIX 1.8.1。

我执行以下步骤:创建网络目录:

sudo mkdir -p /var/www/codingvn.com/html
sudo mkdir -p /var/www/vyhn.net/html
sudo mkdir -p /var/www/muabannhadatpro.com/html
sudo mkdir -p /var/www/thenao.info/html

设置权限:

sudo chown -R $USER:$USER /var/www/codingvn.com/html
sudo chown -R $USER:$USER /var/www/vyhn.net/html
sudo chown -R $USER:$USER /var/www/muabannhadatpro.com/html
sudo chown -R $USER:$USER /var/www/thenao.info/html

初始化索引文件:

nano /var/www/codingvn.com/html/index.html
nano /var/www/vyhn.net/html/index.html
nano /var/www/muabannhadatpro.com/html/index.html
nano /var/www/thenao.info/html/index.html

这是文件的内容/var/www/codingvn.com/html/index.html

<html>
  <head>
    <title>Welcome</title>
  </head>
  <body>
    <h1>Success! The codingvn.com server block is working!</h1>
  </body>
</html>

这是文件的内容/var/www/vyhn.net.com/html/index.html

<html>
  <head>
    <title>Welcome</title>
  </head>
  <body>
    <h1>Success! The vyhn.net server block is working!</h1>
  </body>
</html>

这是文件的内容/var/www/muabannhadatpro.com/html/index.html

<html>
  <head>
    <title>Welcome</title>
  </head>
  <body>
    <h1>Success! The muabannhadatpro.com server block is working!</h1>
  </body>
</html>

这是文件的内容/var/www/thenao.info/html/index.html

<html>
  <head>
    <title>Welcome</title>
  </head>
  <body>
    <h1>Success! The thenao.info server block is working!</h1>
  </body>
</html>

我复制默认配置文件:

sudo cp /etc/nginx/conf.d/default.conf /etc/nginx/sites-available/codingvn.com.conf
sudo cp /etc/nginx/conf.d/default.conf /etc/nginx/sites-available/vyhn.net.conf
sudo cp /etc/nginx/conf.d/default.conf /etc/nginx/sites-available/muabannhadatpro.com.conf
sudo cp /etc/nginx/conf.d/default.conf /etc/nginx/sites-available/thenao.info.conf

我编辑它们:

sudo nano /etc/nginx/sites-available/codingvn.com.conf
sudo nano /etc/nginx/sites-available/vyhn.net.conf
sudo nano /etc/nginx/sites-available/muabannhadatpro.com.conf
sudo nano /etc/nginx/sites-available/thenao.info.conf

这是文件codingvn.com.conf

server {
    listen  80;
    server_name codingvn.com www.codingvn.com;

    location / {
        root  /var/www/codingvn.com/html/index.html;
        index  index.html index.htm;
    }

    error_page  500 502 503 504  /50x.html;
    location = /50x.html {
        root  /usr/share/nginx/html;
    }
}

X

这是文件vyhn.net.conf

server {
    listen  80;
    server_name vyhn.net www.vyhn.net;

    location / {
        root  /var/www/vyhn.net/html/index.html;
        index  index.html index.htm;
    }

    error_page  500 502 503 504  /50x.html;
    location = /50x.html {
        root  /usr/share/nginx/html;
    }
}

X

这是文件muabannhadatpro.com.conf

server {
    listen  80;
    server_name muabannhadatpro.com www.muabannhadatpro.com;

    location / {
        root  /var/www/muabannhadatpro.com/html/index.html;
        index  index.html index.htm;
    }

    error_page  500 502 503 504  /50x.html;
    location = /50x.html {
        root  /usr/share/nginx/html;
    }
}

x 这是文件thenao.info.conf

server {
    listen  80;
    server_name thenao.info www.thenao.info;

    location / {
        root  /usr/share/nginx/html;
        index  /var/www/thenao.info/html/index.html;
    }

    error_page  500 502 503 504  /50x.html;
    location = /50x.html {
        root  /usr/share/nginx/html;
    }
}

每个目录中有 4 个配置文件:

/etc/nginx/sites-available/
/etc/nginx/sites-enable/

然后

service nginx restart

然后编辑主机 /etc/hosts 文件:

104.207.148.242 codingvn.com
104.207.148.242 vyhn.net
104.207.148.242 thenao.info
104.207.148.242 muabannhadatpro.com

那么它们不起作用:

127.0.0.1 codingvn.com
127.0.0.1 vyhn.net
127.0.0.1 thenao.info
127.0.0.1 muabannhadatpro.com

3 个域名仍然无法使用。只能codingvn.com使用。

我困在这里。好累,帮帮我!

相关内容