Nignx 服务器配置

VMware Workstation+CentOS:

测试结构如下:

第一步:下载安装nginx

wget http://nginx.org/download/nginx-1.6.3.tar.gz

tar zxvf nginx-1.6.3.tar.gz
cd nginx-1.6.3
./configure

当 ./configure出现问题时部分解决方法如下:

安装pcre-devel解决问题
yum -y install pcre-devel

安装错误提示:./configure: error: the HTTP cache module requires md5 functions
yum -y install openssl openssl-devel

 

默认安装路径是安装在 /usr/local/nginx 

2.nginx 代理服务器配置

1、进入配置文件目录 cd /usr/local/nginx/conf 

2、为了避免错误修改建议先备份nginx.conf文件命令如下:

cp nginx.conf nginx.conf.bak

3.修改nginx.conf配置文件

vi nginx.conf 按 i 进入修改 

添加以下配置:

upstream productapi{

#ip_hash;

server 192.168.197.1/:9000 weight=1 max_fails=2 fail_timeout=2;

server 10.8.33.16:9000 weight=1 max_fails=2 fail_timeout=2;

}

 

server {
listen 80;
server_name localhost;

#charset koi8-r;

#access_log logs/host.access.log main;

location / {

proxy_pass http://productapi;


proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

按 :wq  保存并退出

虚拟机测试访问注意:

链路地址不能直接解析,应该通过虚拟机外部地址进行访问

访问http://192.168.197.1  按F5刷新可访问

posted on 2015-07-01 18:17  tomfang  阅读(341)  评论(0)    收藏  举报