CentOS7.0安装Nginx1.9.6

前端之家收集整理的这篇文章主要介绍了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

配置

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;
        }

    }
}
原文链接:https://www.f2er.com/centos/380705.html

猜你在找的CentOS相关文章