# Nginx 配置

📆 2021-12-28 15:22

# Https

server {
    listen 443;
    server_name www.tun6.com;

    ssl on;
    ssl_certificate /home/certs/www.tun6.com.pem; # CA PEM
    ssl_certificate_key /home/certs/www.tun6.com.key; # CA Key
    ssl_session_timeout 5m;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
    ssl_protocols SSLv2 SSLv3 TLSv1.2 TLSv1.1 TLSv1;
    ssl_prefer_server_ciphers on;

    location / {
        proxy_pass http://localhost:8080/;
    }
}

# Http

server {
    listen 80;
    server_name tun6.com www.tun6.com;
    location / {
        alias /home/tun6_com/;
    }
}

# 指向文件

server {
    listen 80;
    server_name tun6.com;
    location /file.txt {
        alias /home/tun6_com/file_name.txt;
    }
}

# 指向目录

server {
    listen 80;
    server_name tun6.com;
    location /files/ {
        alias /home/tun6_com/files/;
    }
}

# 设置最大可上传文件大小

http {
    client_max_body_size 10M; # 最大可上传10M的文件
}

# 增加跨域 CROS

server {
    listen 80;
    server_name tun6.com;
    location /files/ {
        add_header Access-Control-Allow-Origin http://static.tun6.com; # 只允许 http://static.tun6.com 可跨域访问
        # add_header Access-Control-Allow-Origin *; # 允许所有 Host 可跨域访问
        alias /home/tun6_com/files/;
    }
}

# 302 永久重定向

server {
    listen 80;
    server_name tun6.com;
    
    rewrite ^/files(.*) https://www.tun6.com/files2$ permanent;
}
最后更新于: 8/16/2022, 2:48:47 PM