Nginx配置http服务器

Nginx配置http服务器

1、配置nginx.conf文件

修改nginx可执行文件目录下的nginx.conf文件

 #配置虚拟主机的
  server {
  	    #虚拟主机访问的端口
        listen       81;
        #虚拟主机访问的域名
        server_name  www.yl.com;
        #静态资源存储的位置
        location / {
            #配置静态资源存放的绝对路径
            root /home/hadoop/www/html;
            #访问首页的文件名
            index index.html;
        }
    }

2、新建静态资源存储目录

新建nginx.conf中配置的静态资源存储目录,在目录新建index.html文件,编写首页html

3、添加虚拟机ip映射

在虚拟机hosts文件中添加ip映射,eg:192.168.84.128 www.yl.com

#修改hosts文件的命令
vi /etc/hosts

4、添加windows的ip映射

在C:WindowsSystem32driversetc此路径(针对window10)中编辑hosts文件,添加ip映射,eg:

192.168.84.128 www.yl.com

5、启动nginx服务并访问

启动nginx服务后,在浏览器中输入http://www.yl.com:81即可访问刚才部署的服务器

记得快乐
原文地址:https://www.cnblogs.com/Y-wee/p/14110538.html