Linux下Nginx配置多域名及SSL证书
    		       		warning:
    		            这篇文章距离上次修改已过437天,其中的内容可能已经有所变动。
    		        
        		                
                
# 定义nginx运行的用户和用户组
user www-data;
 
# 启动进程数
worker_processes auto;
 
# 全局错误日志及PID文件路径
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
 
# 事件模块
events {
    worker_connections 768; # 每个进程的最大连接数
    # 更多的并发连接可以使用"epoll"
    use epoll; # 事件驱动模型
    # 在FreeBSD上使用"kqueue"
    # use kqueue;
}
 
# HTTP服务器配置
http {
    # 设置日志格式
    access_log /var/log/nginx/access.log;
 
    # 默认请求的MIME类型设置
    include /etc/nginx/mime.types;
    default_type application/octet-stream;
 
    # 设置用于网页缓存文件的目录
    client_body_temp_path /var/cache/nginx/client_temp;
    proxy_temp_path /var/cache/nginx/proxy_temp_path;
    fastcgi_temp_path /var/cache/nginx/fastcgi_temp;
    uwsgi_temp_path /var/cache/nginx/uwsgi_temp;
    scgi_temp_path /var/cache/nginx/scgi_temp;
 
    # 设置日志的缓冲时间
    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    # 包含其他的配置文件
    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
 
    # 服务器配置
    server {
        listen 80;
        server_name www.example.com example.com;
        # 重定向HTTP到HTTPS
        return 301 https://$server_name$request_uri;
    }
 
    # SSL证书配置
    server {
        listen 443 ssl http2;
        server_name www.example.com example.com;
 
        # SSL证书和私钥的路径
        ssl_certificate /etc/nginx/ssl/www.example.com.crt;
        ssl_certificate_key /etc/nginx/ssl/www.example.com.key;
 
        # 配置SSL参数
        ssl_protocols TLSv1.2 TLSv1.3;
        ssl_ciphers 'ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384';
        ssl_prefer_server_ciphers on;
 
        # 更多的SSL优化设置
        # ...
 
        # 网站资源的路径
        root /var/www/html;
        index index.html index.htm;
 
        # 网站的其他配置
        # ...
    }
}这个配置文件展示了如何在Nginx中设置多个域名以及如何为每个域名配置SSL证书,同时包含了重定向HTTP到HTTPS的配置。这是一个基本的配置模板,可以根据实际需求进行扩展和调整。
评论已关闭