这是本文档旧的修订版!
Nginx 服务器
主要关于Nginx服务器安装、维护等事项。或者通过 Docker 来管理 Nginx Proxy Manager
安装
安装和多域名设置,主要参考以下文章:1) 2) 3) 4) 5) 6) 按照步骤去做就好,没有太复杂。
sudo apt update sudo apt install nginx sudo systemctl status nginx sudo systemctl reload nginx
安装完并修改配置文件后,检查配置语法是否正确
sudo nginx -t -c dokuwiki.conf # 测试配置文件是否有效 sudo nginx -t # 测试所有设置
端口配置
sudo ufw allow 'Nginx Full' sudo ufw enable sudo ufw status sudo ufw allow ssh # 很重要,否则 SSH 登录会被拒绝
如果出现502拒绝访问,大概是因为php解释服务没有安装。参考 NGINX 502 Bad Gateway: PHP-FPM
sudo apt -y install php7.4 php7.4-fpm # ubuntu 20.04 上只支持 7.4 版本
出现 “PHP function xml_parser_create ” 错误,是因为 php-xml 包没有安装。
sudo apt-get install php-xml
SSL 证书
请参阅 服务器安全设置 笔记中的记述。以开通https
的安全访问模式。
标准配置供参考
server { listen 443 ssl http2 default_server; listen [::]:443 ssl http2 default_server; server_name 你的域名,多个以空格隔开; root 你的博客静态资源路径; ssl_certificate "你上传的 .pem 源证书的路径"; ssl_certificate_key "你上传的 .key 私钥文件路径"; ssl_session_cache shared:SSL:1m; ssl_session_timeout 10m; ssl_ciphers PROFILE=SYSTEM; ssl_prefer_server_ciphers on; include /etc/nginx/default.d/*.conf; location / { } error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } }
反向代理
当访问 http://192.168.17.129:9001/deu/a.html 时,会引导到 http://127.0.0.1:8080
server { listen 9001; server_name 192.168.17.129; location ~ /edu/ { proxy_pass http://127.0.0.1:8080 } location ~ /vod/ { proxy_pass http://127.0.0.1:8081 } }