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 请吧注释的# 部分还原

你可能感兴趣的:(nginx 配置 http重定向到https)