欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

一分钟实现 nginx 配置实现443端口跳转

程序员文章站 2024-03-14 14:03:22
...

配置用于 nginx 配置,实现443端口的跳转

server {
        listen 80;
        server_name abc.com;
        return 301 https://$host$request_uri;            #可用301跳转(选其一)
        rewrite ^(.*)$  https://abc.com$1 permanent; #也可用地址重写规则(选其一)
}
server {
    listen 443 ssl;
    server_name  abc.com;
    ssl_certificate     /etc/nginx/ssl/abc.crt;
    ssl_certificate_key /etc/nginx/ssl/abc.key;
    ssl_session_timeout 5m;
    ssl_protocols  TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers   ALL:!DH:!EXPORT:!RC4:+HIGH:+MEDIUM:-LOW:!aNULL:!eNULL;
    ssl_prefer_server_ciphers  on;
    add_header Access-Control-Allow-Origin *;
    add_header Access-Control-Allow-Headers X-Requested-Wit,content-typeh;
    add_header Access-Control-Allow-Methods GET,POST,OPTIONS;
    location / {
    root  /home/abc;
    }
     access_log  off;
}

配置可用于 php 环境,同时实现443端口的跳转

server {
        listen 80;
        server_name abc.com;
        return 301 https://$host$request_uri;            #可用301跳转(选其一)
        rewrite ^(.*)$  https://abc.com$1 permanent; #也可用地址重写规则(选其一)
}
server {
    listen 443 ssl;
    server_name abc.com;
    ssl_certificate     /etc/nginx/ssl/abc.crt;
    ssl_certificate_key /etc/nginx/ssl/abc.key;
    root /usr/share/nginx/abc.com/;
    index index.php  index.html index.htm;
location ~ \.php($|/) {
        fastcgi_pass  127.0.0.1:9000;
        fastcgi_read_timeout 300;
        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;
        fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
        include         fastcgi_params;
        add_header Access-Control-Allow-Origin *;
        add_header Access-Control-Allow-Headers X-Requested-Wit,content-typeh;
        add_header Access-Control-Allow-Methods GET,POST,OPTIONS;
        }
        location / {
        try_files $uri $uri/ /index.php$is_args$query_string;
                if (!-e $request_filename) {
                    rewrite ^(.*)$ /index.php?s=$1 last;
                    break;
                }
        }
        access_log off;
}