zoukankan      html  css  js  c++  java
  • Nginx核心配置-单节点实现多域

    1.试验环境说明

    1.1 虚拟机环境说明

    [root@nginx-test-10e0e0e22 ~]# uname -r
    3.10.0-957.el7.x86_64
    [root@nginx-test-10e0e0e22 ~]# uname -m
    x86_64
    [root@nginx-test-10e0e0e22 ~]# cat /etc/redhat-release 
    CentOS Linux release 7.6.1810 (Core) 

    1.2 试验环境说明

    在同一台web服务器上基于不同的主机名访问不同的网页内容,具体要求如下:
        访问pc.yanhuihuang.org.cn会得到一个网页内容:
          网页内容自定义。
    
        访问mobile.yanhuihuang.org.cn和mail.yanhuihuang.org.cn内容相同:
          网页内容自定义即可。

    1.3 Nginx源码方式安装步骤

    博主推荐阅读:
                 https://www.cnblogs.com/huihuangyan/p/14501280.html   
    

    2.编辑配置文件并重启服务

    2.1 编辑nginx的主配置文件

    [root@nginx-test-10e0e0e22 ~]#  cat /yanhuihuang/softwares/nginx/conf/nginx.conf
    user  nginx;
    worker_processes  1;
    #worker_cpu_affinity 00000001 ;


    error_log  /yanhuihuang/softwares/nginx/logs/error.log warn;
    pid        /yanhuihuang/softwares/nginx/logs/nginx.pid;


    events {
        worker_connections  1024;
        use epoll;
        accept_mutex on;
        multi_accept on;
    }

    http {
        include       mime.types;
        default_type  application/octet-stream;
        sendfile        on;
        keepalive_timeout  65;
        server {
            listen       80;
            server_name  localhost;
            location / {
                root   html;
                index  index.html index.htm;
            }
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
            }
        }
         
       #导入其他路径的配置文件
         include /yanhuihuang/softwares/nginx/conf.d/*.conf;
     }

    2.2 编辑nginx的子配置文件

    [root@nginx-test-10e0e0e22 ~]#  cat /yanhuihuang/softwares/nginx/conf.d/pc.conf 
    server {
        listen 80;
        server_name pc.yanhuihuang.org.cn;
    
        location / {
            root /yanhuihuang/data/web/nginx/html/pc;
            index index.html;
        }
    
    }
    [root@nginx-test-10e0e0e22 ~]#  cat /yanhuihuang/softwares/nginx/conf.d/mobile.conf 
    server {
        listen 80;
        server_name mobile.yanhuihuang.org.cn mail.yanhuihuang.org.cn;
    
        location / {
            root /yanhuihuang/data/web/nginx/html/mobile;
            index index.html;
        }
    
    }

    2.3 创建测试数据

    [root@nginx-test-10e0e0e22 ~]# mkdir -pv /yanhuihuang/data/web/nginx/html/{pc,mobile}
    mkdir: created directory ‘/yanhuihuang/data/web/nginx/html/pc’
    mkdir: created directory ‘/yanhuihuang/data/web/nginx/html/mobile’
    [root@nginx-test-10e0e0e22 ~]# 
    [root@nginx-test-10e0e0e22 ~]# 
    [root@nginx-test-10e0e0e22 ~]#  echo "<h1 style='color:rgb(255,0,0)'>严辉煌爱陈思婷</h1>" > /yanhuihuang/data/web/nginx/html/pc/index.html
    [root@nginx-test-10e0e0e22 ~]#  echo "<h1 style='color:rgb(0,0,255)'>yhh  love cst 20210309  </h1>" > /yanhuihuang/data/web/nginx/html/mobile/index.html
    [root@nginx-test-10e0e0e22 ~]# 
    [root@nginx-test-10e0e0e22 ~]# 
    [root@nginx-test-10e0e0e22 ~]# 
    [root@nginx-test-10e0e0e22 ~]# systemctl restart nginx 
    [root@nginx-test-10e0e0e22 ~]# 

    3.测试

     

     

  • 相关阅读:

    远见卓识,领导力在于把握企业潮流
    创业者白手起家需要的6个基本因素
    企业领袖的最高境界
    人才招聘中的“笔迹分析技术”
    个人品牌,无法复制的职场优势
    美丽的姑娘,请允许我为你写诗
    重做日志浪费(redo wastage)
    利用Toad for Data Analysts软件生成查询语句
    JailbreakMe.com最新浏览器模式破解iPhones,iPads和iPod Touches方法
  • 原文地址:https://www.cnblogs.com/huihuangyan/p/14507482.html
Copyright © 2011-2022 走看看