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

来源:互联网 发布:flex java 做什么的 编辑:程序博客网 时间:2024/06/06 23:17

因为业务系统需求,需要对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 编译makemake install

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

./configure: error: the HTTP rewrite module requires the PCRE library.You can either disable the module by using --without-http_rewrite_moduleoption, or install the PCRE library into the system, or build the PCRE librarystatically from the source with nginx by using --with-pcre=<path> option.解决:$ apt-get update$ apt-get install libpcre3 libpcre3-dev./configure: error: the HTTP gzip module requires the zlib library.You can either disable the module by using --without-http_gzip_moduleoption, or install the zlib library into the system, or build the zlib librarystatically 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.htmllocation /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 , 进入官网吧

0 0
原创粉丝点击