CentOS7.0安装Nginx1.9.6

CentOS7.0安装Nginx1.9.6

一、安装准备

首先由于nginx的一些模块依赖一些lib库,所以在安装nginx之前,必须先安装这些lib库,这些依赖库主要有g++、gcc、openssl-devel、pcre-devel和zlib-devel 所以执行如下命令安装

yum install gcc-c++
yum install pcre pcre-devel
yum install zlib zlib-devel
yum install openssl openssl–devel
二、安装Nginx

安装之前,最好检查一下是否已经安装有 nginx
find -name nginx

如果系统已经安装了nginx,那么就先卸载
yum remove nginx

首先进入 /usr/local 目录
cd /usr/local

从官网下载最新版的nginx
wget http://nginx.org/download/nginx-1.9.6.tar.gz
tar -zxvf nginx-1.9.6.tar.gz
cd nginx-1.9.6

接下来安装,使用–prefix参数指定nginx安装的目录,make、make install安装
./configure $默认安装在/usr/local/nginx
make
make install

如果没有报错,顺利完成后,最好看一下 nginx 的安装目录
whereis nginx

安装完毕后,进入安装后目录(/usr/local/nginx)便可以启动或停止它了

测试配置文件
/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

停止命令
/usr/local/nginx/sbin/nginx -s stop
启动命令
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
重启
/usr/local/nginx/sbin/nginx -s reload
注意这个
proxy_set_header Host host; host:8080
配置

worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;

upstream web_pools {    
    server 192.168.137.11:8080 weight=5 max_fails=10 fail_timeout=10s;
    server 192.168.137.12:8080 weight=5;
    #server 10.0.0.10:80 weight=5  backup;
}

    server {
        listen       8080;
        server_name   127.0.0.1;
        location / {
            root   html;
            index  index.html index.htm;
            proxy_pass  http://web_pools;
            proxy_set_header Host  $host;
            proxy_set_header X-Forwarded-For $remote_addr;
        }

    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值