最近项目中使用到了Nginx作为反向代理的一些简单功能,但是还是遇到了很多的问题,特在此记录下来,方便后期复看。
https代理到http
场景
服务器只对外暴露https端口,客户端通过https访问到nginx服务器,nginx服务器将对应路径的请求转发到不同的后台处理程序。
解决方案
第一步:查看nginx原有的模块
nginx -V
第二步:切换到源码包重新编译,在原本显示的模块后加上–with-http_ssl_module参数
./configure –prefix=/usr/local/nginx –with-http_stub_status_module –with-http_ssl_module
第三步:编译和安装
make & make install
第四步:修改nginx配置
server {
listen 443 default ssl;
server_name 127.0.0.1;
ssl on;
ssl_certificate /etc/nginx/ssl/server.crt;
ssl_certificate_key /etc/nginx/ssl/server.key;
gzip_static on;
if ($request_method !~* GET|POST|OPTIONS) { return 444; }
location / {
proxy_redirect off;
proxy_pass http://127.0.0.1:8089;
}
location /report/downloadmode {
proxy_pass http://127.0.0.1:8080;
proxy_http_version 1.1;
}
}
第五步:重新加载配置文件
nginx -s reload
注意:配置完成后,客户端就只能通过https://IP访问页面了,除了/report/downloadmode请求转发到http://127.0.0.1:8080,其他所有的请求转发到