開發與維運

Nginx+Tomcat+https動靜分離

什麼是HTTPS?

HTTPS(全稱:Hypertext Transfer Protocol over Secure Socket Layer),是以安全為目標的HTTP通道,簡單講是HTTP的安全版。即HTTP下加入SSL層,HTTPS的安全基礎是SSL,因此加密的詳細內容 就需要SSL。 它是一個URI scheme(抽象標識符體系),句法類同http:體系。用於安全的HTTP數據傳輸。https:URL表明它使用了HTTP,但HTTPS存在不同 於HTTP的默認端口及一個加密/身份驗證層(在HTTP與TCP之間)。這個系統的最初研發由網景公司進行,提供了身份驗證與加密通訊方法,現在它被廣 泛用於萬維網上安全敏感的通訊,例如交易支付方面。

操作環境

前段靜態內容處理:nginx

後端JSP處理:tomcat

一、配置Nginx

Nginx SSL配置指南

二、配置Tomcat

Tomcat SSL配置指南

三、綜合配置

前段靜態內容處理:nginx 配置

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;
    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  /var/log/nginx/access.log  main;
    sendfile        on;
    tcp_nopush      on;
    tcp_nodelay     on;
    server_tokens   off;
    gzip            on;
    gzip_static     on;
    gzip_comp_level 5;
    gzip_min_length 1024;
    keepalive_timeout  65;
    limit_zone   myzone  $binary_remote_addr  10m;
    # Load config files from the /etc/nginx/conf.d directory
    include /etc/nginx/conf.d/*.conf;
}


server {
        listen       80;
        server_name  localhost;
        location ~ .(htm|html|gif|jpg|jpeg|png|ico|rar|css|js|zip|txt|flv|swf|doc|ppt|xls|pdf)$ {
        index index.jsp index.html;
        root /home/tomcat/webapps;
        access_log off;
        expires 24h;
        }#nginx處理靜態內容        
 location /{
        proxy_pass http://127.0.0.1:8080; #提交給後端的tomcat處理         }
}

驗證配置: https://127.0.0.1

Leave a Reply

Your email address will not be published. Required fields are marked *