-
一、安装nginx前需要安装依赖包,一共需要四个包:
- nginx-1.5.8.tar.gz
- pcre-8.31.tar.gz
- zlib-1.2.8.tar.gz
- openssl-fips-2.0.5.tar.gz
二、依次安装openssl-fips-2.0.5.tar.gz, zlib-1.2.8.tar.gz, pcre-8.31.tar.gz, nginx-1.5.8.tar.gz
1.安装openssl-fips-2.0.5.tar.gz
[root@localhost mrms]# tar -zxvf openssl-fips-2.0.5.tar.gz
[root@localhost mrms]# cd openssl-fips-2.0.5
[root@localhost openssl-fips-2.0.5]# ./config
[root@localhost openssl-fips-2.0.5]# make
[root@localhost openssl-fips-2.0.5]# make install
2.安装zlib-1.2.8.tar.gz
[root@localhost mrms]# tar -zxvf zlib-1.2.8.tar.gz
[root@localhost mrms]# cd zlib-1.2.8
[root@localhost zlib-1.2.8]# ./configure
[root@localhost zlib-1.2.8]# make
[root@localhost zlib-1.2.8]# make install
3.安装pcre-8.31.tar.gz
[root@localhost mrms]# tar -zxvf pcre-8.31.tar.gz
[root@localhost mrms]# cd pcre-8.31
[root@localhost pcre-8.31]# ./configure
[root@localhost pcre-8.31]# make
[root@localhost pcre-8.31]# make install
4.安装 nginx-1.5.8.tar.gz
[root@localhost mrms]# tar -zxvf nginx-1.5.8.tar.gz
[root@localhost mrms]# cd nginx-1.5.8
[root@localhost nginx-1.5.8]# ./configure --with-pcre=../pcre-8.31 --with-zlib=../zlib-1.2.8 --with-openssl=../openssl-fips-2.0.5
[root@localhost nginx-1.5.8]# make
[root@localhost nginx-1.5.8]# make install
至此,nginx安装完成!
三、启动nginx
[root@localhost sbin]# ./nginx -c /usr/local/nginx/conf/nginx.conf
四、关于nginx作为应用服务器、反向代码服务器与负载均衡服务器,配置如下
1、应用服务器配置。找到server 80端口,在下面添加
location /file/ {
root /upload;
index index.html index.htm;
}
含义是:当用户访问http://[IP]/file/,会以/upload作为根目录
2、反向代理服务器配置。找到server 80端口,在下面添加
location / {
proxy_pass http://www.test.com:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
含义是:当用户访问http://[IP],会定向到proxy_pass指向的url
3、负载均衡服务器配置。找到server 80端口,在下面添加
location / {
proxy_pass http://mysite;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
在80端口外面,添加
upstream mysite{
server 172.18.71.225:8080;
server 172.25.16.46:8080;
}
以上配置,在nginx重新启动后生效