nginx安装

1、安装依赖包

yum -y install  gcc  gcc-c++  autoconf  automake
yum -y install  zlib*  openssl*
yum -y install  pcre*

2、下载nginx

复制nginx-1.16.0.tar.gz 到/usr/local/soft 下

加压   tar -zxvf  nginx-1.16.0.tar.gz

 

3、安装nginx

cd    nginx-1.16.0

# 查看配置参数

./configure  --help


#配置参数  --prefix安装目录  , 后面2个是http相关模块
./configure --prefix=/usr/local/nginx --with-http_stub_status_module  --with-http_ssl_module


#编译并安装
make   && make install

安装成功后会出现以下日志:

Configuration summary
  + using system PCRE library
  + using system OpenSSL library
  + md5: using OpenSSL library
  + sha1: using OpenSSL library
  + using system zlib library
  nginx path prefix: "/usr/local/nginx"
  nginx binary file: "/usr/local/nginx/sbin/nginx"
  nginx configuration prefix: "/usr/local/nginx/conf"
  nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
  nginx pid file: "/usr/local/nginx/logs/nginx.pid"
  nginx error log file: "/usr/local/nginx/logs/error.log"
  nginx http access log file: "/usr/local/nginx/logs/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"

 

4、测试是否安装成功

cd /usr/local/nginx

.sbin/nginx -v

 

5、修改配置文件

vim  conf/nginx.conf        修改IP 

server {
        listen       80;
        server_name  192.168.8.107; #修改IP

        #charset koi8-r;

        #access_log  logs/host.access.log  main;
       

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

 

6、启动nginx

启动nginx:      ./sbin/nginx   

/usr/local/nging/sbin/nginx  -s  reload     #重新载入配置文件

/usr/local/nging/sbin/nginx  -s  reopen    #重启nginx

/usr/local/nging/sbin/nginx  -s  stop      #停止nginx

查看进程:ps   -ef | grep nginx 

 

访问: http://192.168.8.107:80  , 出现nginx页面,则nginx正常。

 

7、配置负载均衡

修改配置文件nginx.conf

添加upstram模块, 修改location ,加入proxy_pass 

    # 负载均衡
    upstream myserver {
        server 192.168.8.107:8080 weight=1;
        server 192.168.8.107:8081 weight=1;
    }

    server {
        listen       80;
        server_name  192.168.8.107;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;
        location / {
                proxy_pass http://myserver ;
        }

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

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值