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

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

访问成功,到此结束。










评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值