您的位置:首页 > 运维架构 > 反向代理

nginx入门学习——实现简单的反向代理配置(一)

2014-10-16 15:38 926 查看
before

nginx好处就不说了,直接整干货。

最近项目要用nginx,初学,在此记录,以方便自己看。

nginx官网:http://nginx.org/

第一天,实现简单的反向代理配置。

环境

nginx 192.168.12.70

tomcat1 192.168.12.56:80

tomcat2 192.168.12.70:8080

由于环境有限,只有两台虚机,所以把nginx和tomcat2部署到同一台虚机上了。

1.准备nginx的包nginx-1.4.7.tar.gz

下载地址:http://nginx.org/download/nginx-1.4.7.tar.gz

2.解压

tar -zxvf nginx-1.4.7.tar.gz

3.安装依赖程序(如果已经安装了,就不需要安装)

a.gcc

yum install -y gcc

b.pcre

yum install -y pcre

yum install -y pcre-devel

c.zlib

yum install -y zlib

yum install -y zlib-devel

4.编译

cd nginx-1.4.7

./configure --prefix=/opt/icloudq/nginx

运行后如果出现如下代码,证明安装成功:

Configuration summary
+ using system PCRE library
+ OpenSSL library is not used
+ using builtin md5 code
+ sha1 library is not found
+ using system zlib library

nginx path prefix: "/opt/icloudq/nginx"
nginx binary file: "/opt/icloudq/nginx/sbin/nginx"
nginx configuration prefix: "/opt/icloudq/nginx/conf"
nginx configuration file: "/opt/icloudq/nginx/conf/nginx.conf"
nginx pid file: "/opt/icloudq/nginx/logs/nginx.pid"
nginx error log file: "/opt/icloudq/nginx/logs/error.log"
nginx http access log file: "/opt/icloudq/nginx/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"


5.安装

make

make install

6.配置文件

cd /opt/icloudq/nginx/conf

vim nginx.conf

#进程数,建议配置成与cpu核数相同
worker_processes  2;

events {
use epoll;
worker_connections  1024;
}

http {
upstream uec_portal{
#被代理的服务
server 192.168.12.56:80;
server 192.168.12.70:8080;
}

server {
#nginx监听的端口
listen       80;
server_name  localhost;

location / {
#代理
proxy_pass http://uec_portal; }

}
}


7.启动

./opt/icloudq/nginx/sbin/nginx

8.测试

访问地址:http://192.168.12.70:80

访问成功,到此结束。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: