JAVA和Nginx 教程大全

网站首页 > 精选教程 正文

Nginx|Tomcat|一份http转换为https请求的珍藏配置

wys521 2024-09-08 23:02:42 精选教程 46 ℃ 0 评论

前置条件



nginx.conf正文(直接复制粘贴)

改成自己域名、要转发的http地址


#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;
    client_max_body_size  5000m;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;
    
   
     # Tomcat 
    upstream appServer {
        server 127.0.0.1:8080 weight=4;
      
    }
    
      
    server {
       listen       80;
       # listen       somename:8080;
       server_name    域名  ;

      rewrite ^(.*) https://$host$1 permanent;
    }


 server {
        listen      443 ssl; # https  443
        charset     utf-8;
        server_name 域名; # host_name of URL

        #  https
        #ssl on;
        ssl_certificate         证书地址.pem;
        ssl_certificate_key     证书地址.key;

        location / {
            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;

            #  https  Tomcat Tomcat  http 
            proxy_set_header X-Forwarded-Proto $scheme;
            #  Tomcat 
            proxy_pass 自己的http请求;
        }
    }
   



    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}


本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表