一、部署静态网站(ubuntu)
1.1 安装Nginx
1 2 3 4 5 6 7 8
| apt update -y
apt install nginx -y
nginx -v
|
1.2 配置Nginx
创建新的配置文件
1 2
| touch /etc/nginx/conf.d/web.cof vim /etc/nginx/conf.d/web.cof
|
1 2 3 4 5 6 7 8 9 10 11
| server{ listen 80; server_name 你的IP地址;
root 静态网页的地址; index index.html;
location / { try_files $uri $uri/ /index.html; } }
|
1.3 上传静态文件
将打包好的静态文件上传到/var/www/html中
1.4 启动并测试Nginx
1 2 3 4 5 6 7
| service nginx start service nginx status
nginx -t
systemctl reload nginx
|
云服务器放开80端口
二、添加SSL证书
2.1 申请免费证书或者购买证书
2.2 下载站点证书和私钥文件
2.3 将证书和私钥放入云服务中
2.4 配置web.conf
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| server { listen 443 ssl; server_name 你的域名;
# SSL 证书路径 (请替换为你的实际路径)
ssl_certificate 你的站点证书; # 你的站点证书 ssl_certificate_key 你的私钥; # 你的私钥
# 站点根目录等常规配置 root /var/www/html; index index.html index.htm; }
server{ listen 80; server_name 你的域名; return 301 https://$host$request_uri; }
|
2.5 更新nginx配置
云服务器放开443端口
三、Nginxp配置
1 2 3 4
| http:{ server_tokens off; #关闭Nginx版本显示 }
|
本文作者:finyou
本文链接:http://finyou.top/2026/04/16/nginx/http/
版权声明:本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明出处!