Linux下Nginx配置多域名及SSL证书




# 定义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的配置。这是一个基本的配置模板,可以根据实际需求进行扩展和调整。

评论已关闭

推荐阅读

Vue中使用mind-map实现在线思维导图
2024年08月04日
VUE
Web前端最全Vue实现免密登录跳转的方式_vue怎么样不登录返回首页,最强技术实现
2024年08月04日
VUE
vue3 项目搭建教程(基于create-vue,vite,Vite + Vue)
2024年08月04日
VUE
Vue-颜色选择器实现方案——>Vue-Color( 实战*1+ Demo*7)
2024年08月04日
VUE
Vue项目卡顿慢加载?这些优化技巧告诉你!_vue数据多渲染卡顿
2024年08月04日
VUE
vue中的keep-alive详解与应用场景
2024年08月04日
VUE
Vue、React实现excel导出功能(三种实现方式保姆级讲解)
2024年08月04日
vue-office/docx插件实现docx文件预览
2024年08月04日
VUE
java调用js文件的两种方法(支持V8引擎)
2024年08月04日
JavaScript:解决计算精度问题/mathjs/bignumber.js/big.js/decimal.js
2024年08月04日
两周从爬虫小白变大神 _yjs_js_security_passport
2024年08月04日
JS笔记(对象、函数、数组)
2024年08月04日
Markdown.js:强大的纯JavaScript Markdown解析器
2024年08月04日
Vue项目:js模拟点击a标签下载文件并重命名,URL文件地址下载方法、请求接口下载文件方法总结。
2024年08月04日
vue 父组件怎么获取子组件里面的data数据
2024年08月04日
VUE
个人开发实现AI套壳网站快速搭建(Vue+elementUI+SpringBoot)
2024年08月04日
el-table 表格封装并改造实现单元格可编辑
2024年08月04日
none
nodejs环境下创建vue项目、SSH密钥登陆!!!
2024年08月04日
vue+quill+element-ui实现视频、图片上传及缩放保姆级教程,轻松使用富文本
2024年08月04日
【three.js】22. Imported Models导入模型
2024年08月04日