====== Nginx 服务器 ======
主要关于Nginx服务器安装、维护等事项。或者通过 Docker 来管理 [[https://nginxproxymanager.com/|Nginx Proxy Manager]] {{fa>file-text-o}}(([[https://blog.laoda.de/archives/nginxproxymanager|Doc]]))
===== 安装 =====
安装和多域名设置,主要参考以下文章:(([[https://ubiq.co/tech-blog/configure-multiple-host-names-nginx/|How To Configure Multiple Host Names in NGINX]])) (([[https://hackprogramming.com/blog/how-to-setup-subdomain-or-host-multiple-domains-using-nginx-in-linux-server|How to setup subdomain or host multiple domains using nginx in linux server]]))
(([[https://hackprogramming.com/how-to-setup-subdomain-or-host-multiple-domains-using-nginx-in-linux-server/|Subdomain in Nginx]]))
(([[https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-ubuntu-20-04-quickstart-de|Installl Nginx on Ubuntu]]))
(([[https://www.youtube.com/watch?v=liA6Wg-mm2M|Install Video]]))
(([[https://blog.csdn.net/longgeqiaojie304/article/details/84984564|Nginx虚拟主机多host域名配置演示]]))
按照步骤去做就好,没有太复杂。
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解释服务没有安装。参考 [[https://www.datadoghq.com/blog/nginx-502-bad-gateway-errors-php-fpm/|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 证书 ======
请参阅 [[it:server:security#'SSL 证书'|服务器安全设置]] 笔记中的记述。以开通''https''的安全访问模式。
[[https://luyuhuang.tech/2020/06/03/cloudflare-free-https.html|Ngnix 填写方式]]
标准配置供参考
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
}
}
====== Nginx Proxy Manager ======
[[https://lurenjia.top/2022/02/install-nginx-proxy-manager/|安装Nginx Proxy Manager]] / [[https://www.jianshu.com/p/eb945b4769f2|可视化配置Nginx]]
出现错误 ERROR: no matching manifest for linux/s390x in the manifest list entries
> docker pull s390x/node
有效的compose 地址
curl -L "https://github.com/docker/compose/releases/download/$(curl https://github.com/docker/compose/releases | grep -m1 '
====== 调试监测 ======
有三大工具 ''%%htop%%'', ''%%iotop%%'' 以及 ''%%ngxtop%%'',
apt-get install htop, iotp, ngxtop
sudo iotop
pip install ngxtop
ngxtop 是一个python程序, 会调用nginx的日志文件来查阅,''%%i 2%%'' 表示每两秒钟查看一次
ngxtop -l /var/log/nginx/access.log -i 2
nginx 的错误文件和日志文件
sudo cat /var/log/nginx/error.log
sudo cat /var/log/nginx/access.log
{{tag>nginx}}