🐶 ·
安昊
前端研发 · 运维在学
Nginx 入门备忘
记录一些常用的 Nginx 配置,方便以后查阅。
#运维
#Nginx
学运维绕不开 Nginx,整理一下最常用的几个场景。
静态文件托管
最简单的用法,把 Astro 构建产物丢进去:
server {
listen 80;
server_name example.com;
root /var/www/html;
index index.html;
location / {
try_files $uri $uri/ /index.html;
}
}
反向代理
如果后端服务跑在本地端口,用反向代理暴露出去:
location /api/ {
proxy_pass http://127.0.0.1:3000/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
配置 HTTPS
用 certbot 自动申请 Let’s Encrypt 证书:
certbot --nginx -d example.com
certbot 会自动修改 nginx 配置,非常方便。
慢慢补充,用到哪里学到哪里 🔧