nginx 反向代理配置 nginx配置https

来源:互联网 发布:天津快乐十分软件 编辑:程序博客网 时间:2024/06/05 07:48

nginx反向代理配置 
nginx配置https

配置这个转发还是比较简单的,外加https访问,只需要自己获取到相关的SSL证书即可

特别注意,需要先合并证书.crt、.cer文件

#后台转发给tomcatupstream yuming_server{server www.yuming.com:8080;}server{listen 80;listen 443 ssl;server_name www.yuming.com;#ssl                  on;ssl_certificate      D:/phpStudy/nginx/ssl/yuming.crt;ssl_certificate_key  D:/phpStudy/nginx/ssl/yuming.key;index index.html index.htm index.php;root  D:/data/app.gzsh;location ~^/APP/ {  expires 0d;  #缓存作用(30秒/30分钟/2小时/30天)   }location / {   proxy_pass        http://yuming_server;   proxy_cookie_path https://www.yuming.com/ /;   proxy_store off;   proxy_redirect off;   proxy_set_header   Host             $host;   proxy_set_header   X-Real-IP        $remote_addr;   proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;   client_max_body_size 10m;     client_body_buffer_size 128k;     proxy_connect_timeout 90;     proxy_send_timeout 90;     proxy_read_timeout 90;     proxy_buffer_size 4k;     proxy_buffers 4 32k;     proxy_busy_buffers_size 64k;     proxy_temp_file_write_size 64k;     #deny all;}access_log  D:/data/access.log;}

说明:https需要三个文件
下面作为说明

Nginx 部署SSL证书 (特别注意下面加红内容,需要先合并.crt、.cer文件

#需将.cer  中的内容复制到.crt文件头部,中间不要有空

        a.  查看nginx是否开启ssl

        执行命令: nginx安装目录/sbin/nginx -V, 查看命令结果中是否包含"--with-http_ssl_module",否则请先安装ssl模块

        b.  配置证书到对应的站点

        编辑站点对应的站点配置文件,新增或修改如下内容

        server {

            listen          443 ssl;                                             #将原来的80 修改为443

            ...

            root /www/web/xxxx/public_html;

            ssl_certificate        证书文件路径/_www.domain.com.crt;          #需将_www.domain.com.cer  中的内容复制到这个文件头部,中间不要有空行

            ssl_certificate_key 证书文件路径/_www.domain.com.key;         #证书密钥文件

            ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

            ssl_ciphers ALL:!DH:!EXPORT:!RC4:+HIGH:+MEDIUM:!LOW:!aNULL:!eNULL;

            ...

        }