您当前的位置: 首页 >  nginx

一一哥Sun

暂无认证

  • 2浏览

    0关注

    622博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Day02_05_Nginx教程之基于域名的虚拟主机配置方案

一一哥Sun 发布时间:2019-05-22 13:06:38 ,浏览量:2

Nginx配置虚拟主机 一. 基于域名的虚拟主机配置 1. 需求方案
  • 两个域名指向同一台 Nginx 服务器,用户访问不同的域名显示不同的网页内容;

  • 两个域名是 service.shop.com 和 web.shop.com;

  • Nginx 服务器使用虚拟机 192.168.87.108:80端口.

2. 配置 hosts 文件
  • 通过 host 文件指定 service.shop.com 和web.shop.com 对应 192.168.87.108 虚拟机:

  • 修改 windows或linux系统的 的 hosts 文件:(C:\Windows\System32\drivers\etc)与(/etc/hosts)

配置/etc/hosts文件

3. 创建静态资源目录及文件

在 /usr/local/nginx/www 目录下创建 htmlserver 和 htmlweb 两个目录,并分辨创建两个 index.html 文件,以便区分.

4. 配置虚拟主机
user  www-data;
worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    sendfile        on;

    keepalive_timeout  65;
    
    #基于域名的虚拟主机配置方案
    
    #配置http://service.shop.com:80虚拟主机
    server {
        listen       80; #监听端口号
        server_name  service.shop.com; #域名
        location / {
            root   /usr/local/nginx/www/htmlserver; #静态资源存储位置
            index  index.html index.htm;
        }
    }

    #配置http://web.shop.com:80虚拟主机
    server {
        listen       80;
        server_name  web.shop.com;

        location / {
            root   /usr/local/nginx/www/htmlweb;
            index  index.html index.htm;
        }
    }
}

注意:重新加载一下配置文件

sudo service  nginx reload

配置好后的效果:

关注
打赏
1665624836
查看更多评论
立即登录/注册

微信扫码登录

0.0405s