为PVE7的web管理页面设置域名,方便访问
在上一篇中,已经部署好了PVE环境,那么这次是使用lnmp来给pve-web绑定域,相对具体一些,可能会满足我们的需求……
简述
- 宿主机系统:Debian11
- Web环境:lnmp的nginx
绑定域
既然要绑定,那么宿主机则需要部署一个web服务,博主这里是使用lnmp来安装nginx,是的,仅安装nginx。当然也可以选择apt一把梭,反正怎么开心怎么来喽。
wget http://soft.vpser.net/lnmp/lnmp1.9.tar.gz -cO lnmp1.9.tar.gz && tar zxf lnmp1.9.tar.gz && cd lnmp1.9 && ./install.sh nginx
lnmp
命令了添加解析
到对应服务商管理后台,添加一下所要绑定的域的解析,可以A记录,也可以是AAAA记录,反正指向到宿主机的IP地址就可以了。
放行端口
到对应服务商管理后台(套路云ECS是在安全组里),放行80、443端口,不然下面就算部署好了站点,也访问不了的,如果是使用acme脚本签发,也签发不下来(毕竟连访问都访问不了。当然,DNS Api那种不再讨论的范围)。
建个站点
这个就没啥好记录的,lnmp vhost add 按提示填填写写。
root@debian:~/lnmp1.9# lnmp vhost add
+-------------------------------------------+
| Manager for LNMP, Written by Licess |
+-------------------------------------------+
| https://lnmp.org |
+-------------------------------------------+
Please enter domain(example: www.lnmp.org): web-pve.cimen.club
Your domain: web-pve.cimen.club
Enter more domain name(example: lnmp.org sub.lnmp.org):
domain list: web-pve.cimen.club
Please enter the directory for the domain: web-pve.cimen.club
Default directory: /home/wwwroot/web-pve.cimen.club:
Virtual Host Directory: /home/wwwroot/web-pve.cimen.club
Allow Rewrite rule? (y/n)
You choose rewrite: none
Enable PHP Pathinfo? (y/n)
Disable pathinfo.
Allow access log? (y/n) y
Enter access log filename(Default:web-pve.cimen.club.log):
You access log filename: web-pve.cimen.club.log
Enable IPv6? (y/n)
Disabled IPv6 Support in current Virtualhost.
Add SSL Certificate (y/n) y
1: Use your own SSL Certificate and Key
2: Use Let's Encrypt to create SSL Certificate and Key
3: Use BuyPass to create SSL Certificate and Key
4: Use ZeroSSL to create SSL Certificate and Key
Enter 1, 2, 3 or 4: 4
Please enter your email address: i@cimen.club
Email address i@cimen.club is valid.
Using 301 to Redirect HTTP to HTTPS? (y/n) y
Redirect http://web-pve.cimen.club to https://web-pve.cimen.club
Press any key to start create virtul host...
Test Nginx configure file......
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
Reload Nginx......
Generate SSL Certificate successfully.
================================================
Virtualhost infomation:
Your domain: web-pve.cimen.club
Home Directory: /home/wwwroot/web-pve.cimen.club
Rewrite: none
Enable log: yes
Create database: no
Create ftp account: no
Enable SSL: yes
=>ZeroSSL
IPv6 Support: Disabled
* 如果是使用acme脚本申请ssl失败,那么需要检查解析是否生效(可以去各大站点ping一下)、端口是否开启(比如去ping.pe里使用 “tcp ip地址:80”的方式来测试)。若不通需要检查防火墙配置,不仅仅是机器本身的,服务商后台最好也看看是否有防火墙。使用dns api的方式,需要坚持相关的参数是否正确。
配置饭袋
找到对应的站点配置文件,简单配置一下。这里要特别注意的是,协议为https,包括饭袋里的。
server
{
listen 80;
#listen [::]:80;
server_name web-pve.cimen.club ;
return 301 https://$host$request_uri;
}
server
{
listen 443 ssl http2;
#listen [::]:443 ssl http2;
server_name web-pve.cimen.club ;
index index.html index.htm index.php default.html default.htm default.php;
root /home/wwwroot/web-pve.cimen.club;
ssl_certificate /usr/local/nginx/conf/ssl/web-pve.cimen.club/fullchain.cer;
ssl_certificate_key /usr/local/nginx/conf/ssl/web-pve.cimen.club/web-pve.cimen.club.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;
ssl_ciphers "TLS13-AES-256-GCM-SHA384:TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-128-GCM-SHA256:TLS13-AES-128-CCM-8-SHA256:TLS13-AES-128-CCM-SHA256:EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5";
ssl_session_cache builtin:1000 shared:SSL:10m;
# openssl dhparam -out /usr/local/nginx/conf/ssl/dhparam.pem 2048
ssl_dhparam /usr/local/nginx/conf/ssl/dhparam.pem;
include rewrite/none.conf;
#error_page 404 /404.html;
# Deny access to PHP files in specific directory
#location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }
location / {
proxy_pass https://127.0.0.1:8006;
proxy_http_version 1.1;
proxy_cache_bypass $http_upgrade;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Port $server_port;
}
access_log /home/wwwlogs/web-pve.cimen.club.log;
}
防火墙相关
部署了pve后,默认会安装iptables,那这里就不使用它了,直接用Debian11自带的nftables来管理和配置防火墙规则会优雅很多,也不需要记忆很多的语法。
开启防火墙
由于Debian11虽然自带了nftables防火墙,但它默认是没有启用的,因此如果需要使用它就必须创建开机自启动,不然万一宿主机重启后,nftables防火墙就不自动运行了。
#开机自启动
systemctl enable nftables
#运行nftables
systemctl start nftables
配置规则
就不再重复记录了,有需要的可以移步:Debian 11 上的 nftables防火墙 简单配置(配置文件)
重载规则
这里就直接 systemctl restart nftables
来重启防火墙导入新规则,当然也可以使用 nft -f /etc/nftables.conf
来导入,也很方便的。
碎碎念
为了安全起见,在知道自己常用ip段、或者跳板机ip的情况下,建议限制一下访问来源。如果不清楚就不要设置了,容易把自己也给挡在外面。具体的可以参考这篇文章:linux限制访问来源,创建白名单ip。