nginx 配置 http重定向到https


upstream close_ue{
    server 192.168.0.2:9999;
}

server {
        listen 18001;# 監聽對應公網的80端口
        server_name www.a.com;
       
        root /app/htdocs/project;
        error_page 502 503 504 /404.html;
        return  301 https://$host$request_uri;
}

server {
        listen 18000 ; #監聽對應公網的443端口
        server_name www.a.com;
       
        root /app/htdocs/project;
        error_page 502 503 504 /404.html;
       # ssl on;
       # ssl_certificate ssl/server.crt;
       # ssl_certificate_key ssl/server.key;
       # ssl_session_timeout  5m;   
       #  ssl_session_cache    shared:SSL:1m;  
       # ssl_protocols  TLSv1 TLSv1.1 TLSv1.2;  
       #  ssl_ciphers    #EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH:HIGH:!RC4:!MD5:!aNULL:!eNULL:!NULL:!DH:!EDH:!EXP:+MEDIUM;  
       #  ssl_prefer_server_ciphers   on;   
        location ~ .*\.(gif|jpg|png|jpeg|css|js|flv|ico|swf)(.*) {
             expires 1d;
        }
    location / {  
        index index.html index.php; 
        if (!-e $request_filename) {  
       rewrite ^(.*)$ /index.php?s=$1 last; 
           rewrite ^/(.*)$  /index.php/$1  last;  
           break;  
        }  
    }  
    location ~ /.*\.php/ {
                rewrite ^(.*?/?)(.*\.php)(.*)$ /$2?s=$3 last;
                break;
    }
       location ~ \.php$ {
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME /app/htdocs/project$fastcgi_script_name;
            include       fastcgi_params;
       }

   
    location /appEgp {
        proxy_pass  http://close_ue;

        #Proxy Settings
        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;
        proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
        proxy_max_temp_file_size 0;
        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;
   }
}

 我這里是負載均衡的內網服務器配置 外網配置了https 和證書 所以內網不需要配了 如果要配置https 請吧注釋的# 部分還原


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM