磕磕碰碰搭建Nginx实现接口映射

内网的一个web服务器地址需要映射到外网,但只想将一个接口代理出去,所以简单使用nat方式实现不了的,所以想采用Nginx反向代理方式。
1.下载nginx 
http://nginx.org/download/

2.解压缩
hsb@linux-zoxb:~> sudo chmod -777 nginx-1.19.6.tar.gz
hsb@linux-zoxb:~> tar -zxvf nginx-1.19.6.tar.gz

3.安装Nginx
./configure --prefix=/usr/local/nginx --with-pcre --with-http_stub_status_module --with-http_ssl_module
checking for OS
 + Linux 4.4.73-5-default x86_64
checking for C compiler ... not found

./configure: error: C compiler cc is not found
第一次失败,需要安装了gcc-c++

安装gcc后,再继续安装nginx。
第二次失败,遇到错误提示需要pcre
./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.

这玩意SUSE linux 里面没有,找到一个下载地址
https://sourceforge.net/projects/pcre/files/latest/download
hsb@linux-zoxb:~> sudo chmod -777 pcre2-10.36.tar.gz
hsb@linux-zoxb:~> tar -zxvf pcre2-10.36.tar.gz
hsb@linux-zoxb:~>./configure && sudo make && sudo make install #配置编译安装

继续安装。
第三次失败,还是提示找不到prec
hsb@linux-zoxb:~> rpm -ql pcre 提示找不到路径

我安装的Prec2还不行,于是重新去下载pcre
https://sourceforge.net/projects/pcre/files 下载pcre   pcre-8.44.tar.gz
hsb@linux-zoxb:~> sudo chmod -777 pcre-8.44.tar.gz
hsb@linux-zoxb:~> tar -zxvf pcre-8.44.tar.gz
hsb@linux-zoxb:~>./configure && sudo make && sudo make install #配置编译安装
继续安装,prec搞定。

./configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules, or install the OpenSSL library
into the system, or build the OpenSSL library statically from the source
with nginx by using --with-openssl=<path> option.
第四次失败, openssl又出现了
咋不要ssl了。
hsb@linux-zoxb:~>./configure --prefix=/usr/local/nginx --with-pcre --with-http_stub_status_module
./configure: error: the HTTP gzip module requires the zlib library.
You can either disable the module by using --without-http_gzip_module
option, or install the zlib library into the system, or build the zlib library
statically from the source with nginx by using --with-zlib=<path> option.
第五次失败, zlib library又出现了
我也不要了。
hsb@linux-zoxb:~>./configure --prefix=/usr/local/nginx --with-pcre --with-http_stub_status_module --without-http_gzip_module
终于通过,继续安装
hsb@linux-zoxb:~>make
hsb@linux-zoxb:~>sudo make install

4.启动nginx
hsb@linux-zoxb:~/nginx-1.19.6> sudo /usr/local/nginx/sbin/nginx
终于可以用浏览器访问了,安装成功

5.设置nginx开机自动启动
hsb@linux-zoxb:~/nginx-1.19.6> sudo vi /etc/init.d/after.local

6.配置
因为不是静态网页,配置这里折腾了很久,最后反正成功了。
    #gzip  on;
    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main
        location / {
            root   html;
            index  index.html index.htm;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $http_host;
            proxy_set_header X-Nginx-Proxy true;
            proxy_pass http://10.1.2.20:8787/$request_uri;
        }
        #limite login.jsp
        if ($request_uri ~* "/login.jsp") {
        return 403;
}
--重启nginx生效
sudo nginx -c /usr/local/etc/nginx/nginx.conf
nginx -s reload


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值