Ubuntu 使用 nginx 搭建 https 文件服务器

Ubuntu 使用 nginx 搭建 https 文件服务器


搭建步骤

  1. 安装 nginx
  2. 生成证书
  3. 修改 config
  4. 重启 nginx

安装 nginx

apt 安装:

bash 复制代码
sudo apt-get install nginx

生成证书

使用 openssl 生成证书:

到对应的路径下:/etc/nginx/ssl/

bash 复制代码
openssl genrsa -des3 -out shidian.key 1024
openssl req -new -key shidian.key -out shidian.csr
cp shidian.key shidian.key.org
openssl rsa -in shidian.key.org -out shidian.key
openssl x509 -req -days 365 -in shidian.csr -signkey shidian.key -out shidian.crt

修改 config

修改 nginx 对应的 config 文件:/etc/nginx/site-enable/default

bash 复制代码
# SSL配置
server {
    listen 443 ssl;   #SSL协议访问端口号为443。此处如未添加ssl,可能会造成Nginx无法启动。
    server_name localhost;  #(改)将localhost修改为您证书绑定的域名,例如:www.example.com。
    #index index.htm index.html; #默认文件
    #root /usr/share/nginx/html/;
    ssl_certificate /etc/nginx/ssl/shidian.crt;
    ssl_certificate_key /etc/nginx/ssl/shidian.key;
    ssl_session_timeout 5m;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;   #使用该协议进行配置。
    ssl_prefer_server_ciphers on;
    
    #wordpress伪静态,不是wordpress应该就不用加了
    location / {
	    root /usr/share/nginx/html;
	    autoindex on;
	    autoindex_exact_size off;
	    autoindex_localtime on;
	    charset utf-8;
        }
    
    #这段是必备,没有好像就不能正常运行,加了就是了
    location ~* \.(eot|ttf|woff|woff2)$ {
        add_header Access-Control-Allow-Origin '*';
    }
}

重启 nginx

bash 复制代码
sudo nginx -t #测试配置是否正确
sudo nginx -s reload
相关推荐
虎头金猫3 天前
4K 视频总卡在公网带宽?用 N1 + OpenList 把网盘播放链路重新理顺
运维·服务器·网络·python·容器·beautifulsoup·pandas
还是大剑师兰特3 天前
解决nginx错误:http://localhost:7000正常,http://localhost:7000/map 报错404
nginx·大剑师
xing-xing3 天前
Docker容器中Nginx站点根目录网页配置访问
nginx·docker
-梅3 天前
linux(8) 软硬链接
linux·运维·服务器
Wang's Blog3 天前
Java 项目实战: 外卖平台-文件下载与ServletOutputStream回写浏览器
服务器·项目开发
琥珀色糖3 天前
SimlpeHttp
linux·服务器
第十人i3 天前
Linux 日志管理系统:journald 配置与优化
linux·服务器
ITxiaobing20233 天前
IP 定位服务选型指南:从准确率到工程落地的技术考察
linux·服务器·网络
wuyk5553 天前
【Socket 进阶之路】第 9 章 Linux 网络服务量产稳定性优化|心跳保活、TIME_WAIT、SO_LINGER、内存池、断线重连、完整异常防护框架
linux·服务器·开发语言·网络·物联网
Julien20043 天前
Docker 容器存储原理(一)
linux·运维·服务器·ssh·学习方法