搭建nginx的反向代理服务器

1.搭建nginx的反向代理服务器:
        需求:
            linux01:
                部署nginx(192.168.23.110)
            linux02:
                tomcat(真实的服务器端)(192.168.23.111)
            浏览器就是客户端
                访问192.168.23.110--->显示出来的必须是tomcat的主页面(localhost:8080)
        1.1.使用XFTP工具把nginx压缩包上传Linux服务器上
        1.2.解压nginx压缩包
            tar -zxvf nginx....
        1.3.生成快捷方式(usr/local目录)
            必须要在nginx的目录中去执行
            ./configure --prefix=/usr/local/nginx-1.17.9(默认该文件夹是不存在,需要手动输入,名称必须要和/home/apps/nginx-1.17.9一模一样)
        1.4.发现报错了
            ./configure: error: the HTTP rewrite module requires the PCRE library.
            You can either disable the module by using --without-http_rewrite_module
            option, or install the PCRE library into the system, or build the PCRE library
            statically from the source with nginx by using --with-pcre=<path> option.
            咱们已经想开始使用nginx,但是nginx所需要的这些类库Linux是不自带的,需要自己去下载
        1.5.下载nginx所必须要的类库
            yum -y install gcc pcre-devel openssl openssl-devel
            看到以下信息说明类库安装成功:
                Installed:
                  openssl-devel.x86_64 0:1.0.1e-58.el6_10                 pcre-devel.x86_64 0:7.8-7.el6                
                Dependency Installed:
                  keyutils-libs-devel.x86_64 0:1.4-5.el6               krb5-devel.x86_64 0:1.10.3-65.el6               
                  libcom_err-devel.x86_64 0:1.41.12-24.el6             libkadm5.x86_64 0:1.10.3-65.el6                 
                  libselinux-devel.x86_64 0:2.0.94-7.el6               libsepol-devel.x86_64 0:2.0.41-4.el6            
                  zlib-devel.x86_64 0:1.2.3-29.el6                    
                Updated:
                  openssl.x86_64 0:1.0.1e-58.el6_10                                                          
                Complete!
        1.6.再次创建快捷方式
            必须要在nginx的解压目录中执行
            ./configure --prefix=/usr/local/nginx-1.17.9
            看到以下信息说明创建成功:
                Configuration summary
              + using system PCRE library
              + OpenSSL library is not used
              + using system zlib library

              nginx path prefix: "/usr/local/nginx-1.17.9"
              nginx binary file: "/usr/local/nginx-1.17.9/sbin/nginx"
              nginx modules path: "/usr/local/nginx-1.17.9/modules"
              nginx configuration prefix: "/usr/local/nginx-1.17.9/conf"
              nginx configuration file: "/usr/local/nginx-1.17.9/conf/nginx.conf"
              nginx pid file: "/usr/local/nginx-1.17.9/logs/nginx.pid"
              nginx error log file: "/usr/local/nginx-1.17.9/logs/error.log"
              nginx http access log file: "/usr/local/nginx-1.17.9/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"

        1.7.编译并安装
            make && make install
            看到以下信息说明编译和安装成功:
                make[1]: Leaving directory `/home/apps/nginx-1.17.9'

        1.8.启动nginx
            在sbin目录中执行:
                !!!这一步一定是要在快捷方式里面完成,nginx解压其实是没有,也就是必须要在/usr/local/nginx-1.17.9下才能找到sbin目录!!!
                ./nginx

        1.9.检测nginx是否启动成功
            打开浏览器直接访问192.168.23.150即可
            看到以下信息说明启动成功:
                Welcome to nginx!

        1.10.配置反向代理
            !!! 所有的操作都必须要在快捷方式中进行配置,否则不生效(/usr/local/nginx-1.17.9/conf目录中完成) !!!
            vim /usr/local/nginx-1.17.3/conf/nginx.conf
            注意事项:
                1.10.1.所有的配置必须要在http{}标签里面完成,否则不生效,而且必须要在server{}标签之上完成
                1.10.2.命名规则:
                    使用的版本为1.15.3之前都开始可以使用连接符(-,=,_等等),但是之后的版本不能使用,否则nginx启动报错
                upstream tomcatServer(这个名字随便起,开心就好,但是不能使用连接符){
                    server 因为要去做转发,所以必须要知道真实服务器端的ip地址是多少
                    server 192.168.23.169:8080;(这个分号千万千万不要忘,要不然启动会报错)
                }
                因为文件解析和编译是按照自然规律,自上而下来进行完成,所以必须要先配置upstream,再配置server,也就是说upstream必须要在server的上面,否则nginx会报错!!!
                配置的其实就是server{}标签中的location /{}
                删除location /{}标签中的所有内容
                location / {
                    proxy_pass http://tomcatServer;(一定要和upstream的名称一模一样,包括大小写,一定也不要忘记带分号和"http://"协议标识)
                }

            1.11.重启nginx服务,让配置生效
                在sbin目录中执行
                ./nginx -s reload
 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值