Centos6.8安装nginx(一)

在这里对nginx的安装简单的做个记录,后续有时间的话在详细补充。

1.yum安装gcc gcc-c++:

yum install -y gcc gcc-c++ [enter]

2.下载必需的依赖库:zlib 、openssl 、pcre

wget http://nginx.org/download/nginx-1.11.13.tar.gz [enter]
wget https://www.openssl.org/source/openssl-1.1.0e.tar.gz [enter]
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre2-10.21.tar.gz [enter]
wget http://www.zlib.net/zlib-1.2.11.tar.gz [enter]

3.安装依赖库:zlib 、openssl 、pcre

tar xvf nginx-1.11.13.tar.gz [enter]
tar xvf openssl-1.1.0e.tar.gz [enter]
tar xvf pcre2-10.21.tar.gz [enter]
tar xvf zlib-1.2.11.tar.gz [enter]
cd ./nginx-1.11.13 [enter]
./configure --prefix=/usr/local/nginx --with-pcre=../pcre2-10.21 --with-openssl=../openssl-1.1.0e --with-zlib=../zlib-1.2.11 [enter]
make [enter]
make install [enter]
注意:--with选项均指向源码路径。

4.修改配置:

vi /usr/local/nginx/conf/nginx.conf [enter]

添加以下内容,注意位置:

upstream  test {
    server   127.0.0.1:18087; 
    server   127.0.0.1:28087;  
}
server {
    listen       80;
    server_name  localhost;
    charset utf-8;
    location /test {
        root   html;
        index  index.html index.htm;
        proxy_pass        http://test;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
    }
}

5.测试配置问是否正确:

/usr/local/nginx/sbin/nginx -t [enter]

出现以下信息为正确:

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

6.启动 :

启动:
/usr/local/nginx/sbin/nginx [enter]
重启:
/usr/local/nginx/sbin/nginx -s reload [enter]

7.访问:

 

安装成功!

先记录到这里,后续再进行详细补充^_^~

相关推荐