nginx反向代理tomcat在linux的部署

来源:互联网 发布:matlab二维数组 编辑:程序博客网 时间:2024/05/01 03:37

在linux部署nginx

nginx的部署需要几个必要模块的支持,包括pcre,gzip,ssl。若系统未部署,则需要先安装这几个模块。(有说在执行nginx configure时指定模块地址即可,未实验。)

        #pcre部署                tar -zxvf pcre-8.21.tar.gz       cd pcre-8.21        ./configuremake        make install
</pre></div><div><span style="white-space:pre"></span><pre name="code" class="plain">#zlib部署(gzip)
tar -zxvf zlib-1.2.7.tar.gz
cd zlib-1.2.7
./configure 
make
make install
</pre></div><div><span style="white-space:pre"></span><pre name="code" class="plain">#ssl部署
tar -zxvf openssl-fips-2.0.2.tar.gz 
cd openssl-fips-2.0.2
./config 
make
make install
</pre></div><div><span style="white-space:pre"></span><pre name="code" class="plain">#ngxin部署
tar -zxvf nginx-1.2.6.tar.gz 
cd nginx-1.2.6
./configure 
make
make install

配置nginx

1、配置mime.types

增加需要的type,如html的appcache类型,ios&android app下载类型

2、配置gzip压缩

gzip on;//该指令用于开启或关闭gzip模块(on/off)
gzip_min_length 1k;//设置允许压缩的页面最小字节数,页面字节数从header头得content-length中进行获取。默认值是0,不管页面多大都压缩。建议设置成大于1k的字节数,小于1k可能会越压越大。
gzip_buffers 4 16k;//设置系统获取几个单位的缓存用于存储gzip的压缩结果数据流。4 16k代表以16k为单位,安装原始数据大小以16k为单位的4倍申请内存
gzip_http_version 1.1;//识别http的协议版本(1.0/1.1)
gzip_comp_level 2;//gzip压缩比,1压缩比最小处理速度最快,9压缩比最大但处理速度最慢(传输快但比较消耗cpu)
gzip_types text/plain application/x-javascript text/css application/xml;//匹配mime类型进行压缩,无论是否指定,”text/html”类型总是会被压缩的。

gzip_vary on;//和http头有关系,加个vary头,给代理服务器用的,有的浏览器支持压缩,有的不支持,所以避免浪费不支持的也压缩,所以根据客户端的HTTP头来判断,是否需要压缩

3、配置反向代理

#配置反向代理服务

upstream xxx_server{

server localhost:8087

}

        #配置反向代理需要拦截的url pattern

location /xxx{

proxy_pass http://xxx_server/xxx;

proxy_set_headerHost $host:$port;#对于非80端口的nginx,配置时要加上$port。

proxy_set_headerX-Real-IP $remote_addr;

proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for;

proxy_set_headerReferer http://$host

}



0 0
原创粉丝点击