美文网首页
Note18:Nginx-1.18.0安装配置

Note18:Nginx-1.18.0安装配置

作者: K__3f8b | 来源:发表于2020-06-23 18:24 被阅读0次

    下载安装

    [kevin@hadoop112 software]$ tar -zxvf nginx-1.18.0.tar.gz
    
    • yum安装依赖包
    # 可能使用到root权限,安装完成依赖记得使用回普通用户
    [root@hadoop112 software]$ yum -y install openssl openssl-devel pcre pcre-devel zlib zlib-devel gcc gcc-c++
    
    • 进入解压缩目录,执行
    [kevin@hadoop112 software]$ cd nginx-1.18.0
    [kevin@hadoop112 nginx-1.18.0]$ ./configure --prefix=/opt/module/nginx-1.18.0
    [kevin@hadoop112 nginx-1.18.0]$ make && make install
    
    • 赋权限
    # nginx占用80端口,默认情况下非root用户不允许使用1024以下端口
    [kevin@hadoop112 nginx-1.18.0]$ cd /opt/module/nginx-1.18.0
    [kevin@hadoop112 nginx-1.18.0]$ sudo setcap cap_net_bind_service=+eip /opt/module/nginx-1.18.0/sbin/nginx
    
    • 启动、关闭命令nginx
    [kevin@hadoop112 nginx-1.18.0]$ cd /opt/module/nginx-1.18.0
    # 启动命令
    [kevin@hadoop112 nginx-1.18.0]$ cd sbin/
    [kevin@hadoop112 sbin]$ ./nginx
    # 关闭命令
    [kevin@hadoop112 sbin]$ ./nginx -s stop
    # 重启
    [kevin@hadoop112 sbin]$ ./nginx -s reload
    
    • 如果启动时报错
    [kevin@hadoop112 sbin]$ ln -s /usr/local/lib/libpcre.so.1 /lib64
    
    • 修改配置文件(conf/nginx.conf)
    [kevin@hadoop112 sbin]$ cd /opt/module/nginx-1.18.0/conf/
    [kevin@hadoop112 conf]$ vim nginx.conf
    
    http{
       ..........
        upstream logserver{
          server    hadoop112:8080 weight=1;  
          server    hadoop113:8080 weight=1;
          server    hadoop114:8080 weight=1;
     
        }
        server {
            listen       80; #监听端口
            server_name  localhost; #域名
     
            location / {
                root   html;
                index  index.html index.htm;
                proxy_pass http://localhost; #域名
                proxy_connect_timeout 10;
             }
       ..........
    }
    
    • 启动 查询进程
    [kevin@hadoop112 sbin]$ ps -ef | grep nginx
    
    kevin    21040     1  0 18:13 ?        00:00:00 nginx: master process ./nginx
    kevin    21041 21040  0 18:13 ?        00:00:00 nginx: worker process
    kevin    21044 20975  0 18:13 pts/2    00:00:00 grep nginx
    

    相关文章

      网友评论

          本文标题:Note18:Nginx-1.18.0安装配置

          本文链接:https://www.haomeiwen.com/subject/gqtdfktx.html