Nginx Tomcat http 强制跳转https ssl crt key

user  www www;
worker_processes auto;
error_log  /home/wwwlogs/nginx_error.log  crit;
pid        /usr/local/nginx/logs/nginx.pid;
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 51200;
events
    {
        use epoll;
        worker_connections 51200;
        multi_accept on;
    }
http
    {
        include       mime.types;
        default_type  application/octet-stream;
        server_names_hash_bucket_size 128;
        client_header_buffer_size 32k;
        large_client_header_buffers 4 32k;
        client_max_body_size 50m;
        sendfile on;
        tcp_nopush     on;
        keepalive_timeout 60;
        tcp_nodelay on;
        fastcgi_connect_timeout 300;
        fastcgi_send_timeout 300;
        fastcgi_read_timeout 300;
        fastcgi_buffer_size 64k;
        fastcgi_buffers 4 64k;
        fastcgi_busy_buffers_size 128k;
        fastcgi_temp_file_write_size 256k;
        gzip on;
        gzip_min_length  1k;
        gzip_buffers     4 16k;
        gzip_http_version 1.0;
        gzip_comp_level 2;
        gzip_types       text/plain application/x-javascript text/css application/xml;
        gzip_vary on;
        gzip_proxied        expired no-cache no-store private auth;
        gzip_disable        "MSIE [1-6]\.";
        server_tokens off;
        log_format  access  '$remote_addr - $remote_user [$time_local] "$request" '
        '$status $body_bytes_sent "$http_referer" '
        '"$http_user_agent" $http_x_forwarded_for';


server
    {
            listen       80;
            server_name 192.168.1.150;
            index index.html index.htm index.php default.html default.htm default.php;
            root        /home/wwwroot/default;
location /logs {
 alias ../logs;
 #Nginx日志目录
 
 autoindex on;
 #打开目录浏览功能
 
 autoindex_exact_size off;
 #默认为on,显示出文件的确切大小,单位是bytes
 #显示出文件的大概大小,单位是kB或者MB或者GB
 
 autoindex_localtime on;
 #默认为off,显示的文件时间为GMT时间。
 #改为on后,显示的文件时间为文件的服务器时间
 
 add_header Cache-Control no-store;
 #让浏览器不保存临时文件
}


location /status {
   stub_status on;
   access_log /usr/local/nginx/logs/status.log;    #日志
   auth_basic "NginxStatus";            
}


            location ~ \.php($|/) {
                fastcgi_pass   unix:/tmp/php-cgi.sock;
                fastcgi_index  index.php;
                fastcgi_split_path_info ^(.+\.php)(.*)$;
                fastcgi_param   PATH_INFO $fastcgi_path_info;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                include        fastcgi_params;
            }


            location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
                    {
                            expires      30d;
                    }


            location ~ .*\.(js|css)?$
                    {
                            expires      12h;
                    }
            if (!-e $request_filename) {
                rewrite ^/(.*)$ /index.php/$1 last;
                break;
            }
    }


upstream httpsTest{
ip_hash;
server 172.16.16.48:8010;
}
server{
listen 8900;
server_name  172.16.14.26;
server_name_in_redirect off;
location / {
proxy_pass http://httpsTest;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# client_max_body_size 1024m;
proxy_set_header Host $http_host;
}
}




  upstream qixin_http{


        ip_hash;
        server 172.16.14.26:8800;
      #server 172.16.16.47:80;
server 172.16.14.26:9900;
server 172.16.14.26:7700;
    }




upstream tomcat_https {
   server 172.16.14.26:7443 fail_timeout=0;
   server 172.16.14.26:8443 fail_timeout=0;
   server 172.16.14.26:9443 fail_timeout=0;
}


# HTTPS server
server {
    listen       443 ssl;
    server_name  172.16.14.26;
   #server_name  tomcat_https;
ssl on;
    ssl_certificate      /usr/local/nginx/conf/bonc.buruohuainian.cn.bundle.crt;
    ssl_certificate_key  /usr/local/nginx/conf/bonc.buruohuainian.cn.key;


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


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


    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-Forwarded-Proto https;
        proxy_set_header X-Real-IP $remote_addr;  
proxy_headers_hash_max_size 51200;
proxy_headers_hash_bucket_size 6400;
        proxy_redirect off;
        proxy_connect_timeout      240;
        proxy_send_timeout         240;
        proxy_read_timeout         240;
        # note, there is not SSL here! plain HTTP is used
        proxy_pass https://tomcat_https;
    }
}




    server {
        listen       8010;
        server_name  qixin_http;
# rewrite ^(.*)$ https://$host:443 permanent;   
        return 301 https://$host:2611$request_uri;
        server_name_in_redirect off;
        #location / {
        #    root   html;
        #    index  index.html index.htm;
        #}
location /logs {
 alias ../logs;
 #Nginx日志目录


 autoindex on;
 #打开目录浏览功能


 autoindex_exact_size off;
 #默认为on,显示出文件的确切大小,单位是bytes
 #显示出文件的大概大小,单位是kB或者MB或者GB


 autoindex_localtime on;
 #默认为off,显示的文件时间为GMT时间。
 #改为on后,显示的文件时间为文件的服务器时间


 add_header Cache-Control no-store;
 #让浏览器不保存临时文件
}
location /status {
   stub_status on;
   access_log /usr/local/nginx/logs/status.log;    #日志
   auth_basic "NginxStatus";            
}


        location / {
            proxy_pass http://qixin_http;   #来自jsp请求交给tomcat处理
            proxy_redirect off;
            proxy_set_header Host $http_host;    #后端的Web服务器可以通过X-Forwarded-For获取用户真实IP
            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;   #nginx跟后端服务器连接超时时间(代理连接超时)
            proxy_read_timeout 90;      #连接成功后,后端服务器响应时间(代理接收超时)
            proxy_buffer_size 4k;       #设置代理服务器(nginx)保存用户头信息的缓冲区大小
            proxy_buffers 6 32k;        #proxy_buffers缓冲区,网页平均在32k以下的话,这样设置
            proxy_busy_buffers_size 64k;#高负荷下缓冲大小(proxy_buffers*2)
            proxy_temp_file_write_size 64k; #设定缓存文件夹大小,大于这个值,将从upstream服务器传
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

    }

}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 要实现nginx http自动https,需要在nginx配置文件中添加以下代码: ``` server { listen 80; server_name yourdomain.com; return 301 https://$server_name$request_uri; } ``` 其中,yourdomain.com需要替换成你的域名。 这段代码的作用是监听80端口,当有http请求访问时,自动将请求重定向到443端口的https协议。 添加完毕后,需要重新加载nginx配置文件,使其生效。可以使用以下命令: ``` sudo nginx -s reload ``` 这样,当用户访问你的网站时,如果使用http协议,会自动https协议,保证网站的安全性。 ### 回答2: Nginx是一个非常流行的Web服务器和反向代理服务器。它可以用于许多用途,其中之一是将HTTP自动重定向到HTTPS。这是因为HTTPS是一个更安全的协议,可保护用户的隐私和敏感信息。 要实现HTTP自动重定向到HTTPS,必须进行以下操作: 1.在Nginx配置文件中添加HTTPS服务器块。这是必要的,因为HTTPS服务器需要证书和密钥来进行加密通信。可以在一台服务器上设置多个服务器块,每个服务器块可以具有不同的IP地址或端口。 2.在HTTP服务器块中添加重定向指令。有两种常用的重定向指令可以使用。一种是使用return指令,它将客户端的URL重定向到指定的URL。另一种是使用rewrite指令,它允许您对URL进行更复杂的重定向操作,包括更改QUERY_STRING和其他操作。 3.将HTTP服务器块更改为重定向到HTTPS服务器块。可以将所有的HTTP请求都重定向到HTTPS服务器块。这可以通过在HTTP服务器块中添加server_name指令来实现,该指令将包含匹配的主机名。然后可以使用重定向指令将客户端的URL重定向到对应的HTTPS服务器块。 4.配置HTTPS服务器块以使用SSL。必须使用NginxSSL模块来配置服务器块以使用SSL。这可以通过在块中添加ssl on指令来实现。还需要配置SSL证书和密钥。 完成上述步骤后,Nginx将自动将HTTP请求重定向到HTTPS。这可以确保在用户进行通信时保护敏感信息的安全性。 ### 回答3: Nginx是一款流行的Web服务器和反向代理服务器,它可以处理大量的HTTP请求和静态文件。许多网站都要求将HTTP请求自动发到HTTPS,以确保网站的安全性。在此过程中,Nginx可以帮助我们实现HTTP自动HTTPS。今天,我们将探讨如何在Nginx上实现HTTP自动HTTPS。 要实现HTTP自动HTTPS,我们需要在Nginx的服务器配置中添加以下代码: server { listen 80; server_name yourdomain.com; return 301 https://$server_name$request_uri; } 通过添加此代码段,我们可以在Nginx服务器中定义一个HTTP服务监听端口。当HTTP请求到达时,它将会自动发到HTTPS。返回的“301”是一个重定向HTTP代码,它告诉浏览器当前请求被永久重定向到HTTPS。 您还可以使用以下代码实现HTTPHTTPS服务器的配置: server { listen 80; server_name yourdomain.com; return 301 https://$server_name$request_uri; } server { listen 443 ssl; server_name yourdomain.com; ssl_certificate /path/to/ssl.crt; ssl_certificate_key /path/to/ssl.key; # HTTPS server configuration } 在这个配置中,我们提供了两个服务器块,一个是HTTP服务器块,另一个是HTTPS服务器块。与前面的服务器配置段类似,此配置要求HTTP请求被自动重定向到HTTPS。 总结: 使用NginxHTTP请求自动重定向到HTTPS对网站安全至关重要。实现这一目标的最简单方法是在Nginx服务器的配置中定义HTTP服务器监听端口并使用“301”代码自动将请求发到HTTPS。通过正确的配置和实现,您可以确保您的站点在网络中的安全性和可靠性。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值