服务器部署---《nginx篇》 --菜鸟慧言.md

服务器部署—《nginx篇》


汇总篇:
服务器配置篇汇总(linux)+(jdk)+(tomcat)+(mysql)+(nginx)+(redis)+(fastDFS)+(mycat)
接上篇:
服务器部署—《mysql篇》


四、nginx(安全组开启所配置端口)

  1. 创建:mkdir /opt/nginx

  2. 进入:cd /opt/nginx/

  3. 下载:wget http://file.huijia21.com/file/nginx-1.13.0.tar.gz

  4. 解压:tar -zxvf nginx-1.13.0.tar.gz

  5. 编译:

    1
    2
    3
    4
    5
    6
    7
    cd nginx-1.13.0
    //安装编译源码所需要的工具和库:
    yum install gcc gcc-c++ ncurses-devel perl
    yum install pcre pcre-devel
    yum install zlib gzip zlib-devel
    //编译
    ./configure
  6. 安装到默认位置/usr/local/nginx:make & make install
    image-20220430211126489

  7. 启动

    1
    2
    3
    4
    5
    cd /usr/local/nginx/sbin/
    //启动
    ./nginx
    //重启
    ./nginx -s reload

    image-20220430211135391

  8. 虚拟主机配置

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    vi /usr/local/nginx/conf/nginx.conf
    //在原主页server上写入:

    # 虚拟主机的配置

    #虚拟主机一(虚拟域名):
    server {
    listen 8081; #端口
    server_name hhh.idse.top; #域名,虚拟机需要在windows的C:\Windows\System32\drivers\etc的hosts里面配置
    #120.27.244.176 hhh.idse.top
    location / {
    root abc; #相当于ningx目录下的hbq目录,可以写成绝对路径 /zhiyou/java
    index a.html; #默认跳转页面
    }
    }
    #虚拟主机一(真实域名):
    server {
    listen 8082; #端口
    server_name www.idse.top; #公网域名,配置域名解析到本机ip

    location / {
    root abc; #相当于ningx目录下的hbq目录,可以写成绝对路径 /zhiyou/java
    index b.html; #默认跳转页面
    }
    }
    #虚拟主机三(ip):
    server{
    listen 8083; #端口
    server_name 120.27.244.176; #域名
    location / {
    root abc; #相当于ningx目录下的hbq目录,可以写成绝对路径 /zhiyou/java
    index c.html; #默认跳转页面
    }
    }
    //创建文件
    mkdir -p /usr/local/nginx/abc
    vi /usr/local/nginx/abc/a.html //写入aaa
    vi /usr/local/nginx/abc/b.html //写入bbb
    vi /usr/local/nginx/abc/c.html //写入ccc
    //重启nginx
    cd /usr/local/nginx/sbin/
    ./nginx -s reload

    image-20220430211145872

  9. 负载均衡多服务器配置

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    upstream tomcatserver1 {   #后面的名字自己起的,与下面proxy_pass后面保持一致
    server 120.27.244.176:8080 weight=2; #ip或者主机名都可以
    #server 120.27.244.176:81;
    }
    server {
    listen 80; #端口
    server_name www.idse.top; #域名,虚拟机需要在windows的hosts里面配置

    location / {
    proxy_pass http://tomcatserver1; #代理,会更具名字找到上面的
    }
    }

    image-20220430211153673


接下篇:
服务器部署—《redis篇》