Nginx

一、什么叫Nginx?

  1.Nginx (engine x) 是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP服务器。

  2.Nginx作为负载均衡服务器。

  3.稳定性、丰富的功能集、示例配置文件和低系统资源的消耗(能够支持高达 50,000 个并发连接数的响应)

二、安装Nginx  

1.解压nginx-1.13.6.tar.gz
  tar -zxvf nginx-1.13.6.tar.gz
2.安装编译环境
    #gcc
    yum install gcc-c++
    #pcre
    yum install -y pcre pcre-devel
    #zlib
    yum install -y zlib zlib-devel
    #openssl
    yum install -y openssl openssl-devel
3.编译源码
    cd nginx-1.13.6
    ./configure --prefix=/root/soft/nginx-bin
    make
    make install
4.启动&停止
    nginx-bin/sbin/nginx   #启动,如果出现403将  conf/nginx.conf  头部添加user  root;(默认使用conf/nginx.conf)
    nginx-bin/sbin/nginx -c  配置文件路径
    停止:
    nginx-bin/sbin/nginx -s stop
    
    nginx-bin/sbin/nginx -s reload   重新加载配置文件
    
    访问:ip地址加80端口,默认可以不写!

三、使用Nginx

  1.主要是配置文件

主要是配置文件:
    http {
     # 就是一个虚拟主机
      server {
        # 需要拦截的URL
        location  {
          # 查找资源的目录
          root  html;
          # 主界面
          index index.html;
        }
      }
    }

  2.配置主机域名

配置主机域名:
    1.C:WindowsSystem32driversetchosts
    2.需要配置文件中配置如下配置
    server {
        listen       80;
        server_name  www.sina.com;

        location / {
            root   sina;
            index  index.html;
        }
    }

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

        location / {
            root   html;
            index  index.html index.htm;
        }
    }

  3.反向代理    使用nginx去代理tomcat

反向代理    使用nginx去代理tomcat
    # 反向代理
    upstream sina {
       server  localhost:8081 weight=10;
       # 负载均衡
       server  localhost:8082 weight=1;  
    }
   
    server {
        listen       80;
        server_name  localhost;

        location / {
            proxy_pass   http://sina;
            # root   html;
            # index  index.html index.htm;
        }

     } 
原文地址:https://www.cnblogs.com/MrXiaoAndDong/p/Nginx.html