远程服务器上nginx安转与基本操作(ip反向代理转发)

因为业务系统需求,需要对web服务作nginx代理,在不断的尝试过程中,简单总结了一下常见的nginx代理配置。

下载安装

下载源码

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

这是1.2.8版本其他版本自己下载。

安装

#解压
tar -zxvf nginx-1.2.8.tar.gz
#进入目录
cd nginx-1.2.8  
配置安转目录
./configure --prefix=/usr/local/nginx --with-stream
编译
make
make install

——————————————-分界线开始—————————————-
最近配置的时候报错缺少依赖如下:

./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.
解决:
$ apt-get update
$ apt-get install libpcre3 libpcre3-dev

# wget http://sourceforge.net/projects/pcre/files/pcre/8.32/pcre-8.32.tar.gz/download
# tar -xzvf pcre-8.32.tar.gz
# cd pcre-8.32
# ./configure --prefix=/usr/local/pcre
# make && make install

./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.
解决:
 $  sudo apt-get install zlib1g-dev 

最暴力的解决(可能运行会报错):

$ ./configure --prefix=/usr/local/nginx --without-http_gzip_module 

——————————————-分界线结束—————————————-
至此安装完成

验证

启动:

/usr/local/nginx/sbin/nginx

打开浏览器:

输入安装nginx的ip

出现:
Welcome to nginx!

转发配置

vi /usr/local/nginx/conf/nginx.conf

如图所示

注意两个关键词:location 和proxy_pass
location:就是后缀,proxy_pass:就是转发到的相应的ip及其端口。
如下:

location /{
    proxy_pass http://localhost:8080/index.html
}
#这句话就是说把所有的localhost请求转发到http://localhost:8080/index.html

location /test{
    proxy_pass http://localhost:8080/test/index.html
}
#这句话就是说把所有的localhost/test请求转发到http://localhost:8080/test/index.html
#注意:不要location 不要写成 /test/ 因为location的pattern识别的路径作为绝对路径。

是不是很简单,对很简单,不过这是nginx最基础的用法,if you want to more , 进入官网吧

———分界线——-
如果需要使用https相关服务,–with-http_ssl_module

sudo apt-get install openssl libssl-dev

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值