kalacloud@chuan-server:~$ sudo ufw app list
Available applications:
Nginx Full
Nginx HTTP
Nginx HTTPS
OpenSSH
你可以看到 Nginx 提供了三个配置文件:
Nginx Full
开端口80 正常,未加密的网络流量
端口443 TLS / SSL加密的流量
Nginx HTTP
仅打开端口80 正常,未加密
Nginx HTTPS
仅打开端口443 TLS / SSL加密
我们使用 Nginx HTTP 来做本教程演示。
sudo ufw allow 'Nginx HTTP'
我们用以下命令来查看更改结果
sudo ufw status
我们可以在输出结果中看到
Status: active
To Action From
-- ------ ----
OpenSSH ALLOW Anywhere
Nginx HTTP ALLOW Anywhere
OpenSSH (v6) ALLOW Anywhere (v6)
Nginx HTTP (v6) ALLOW Anywhere (v6)
第3步:检查我们的 Web 服务器
在安装结束后,Ubuntu 会启动 Nginx 。 Web 服务器应该已经在运行了。
我们可以通过 systemd 来检查 init 系统状态,确保它正在运行:
systemctl status nginx
kalacloud@chuan-server:~$ systemctl status nginx
● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset:>
Active: active (running) since Wed 2020-07-29 07:21:53 UTC; 23min ago
Docs: man:nginx(8)
Main PID: 3340 (nginx)
Tasks: 2 (limit: 2248)
Memory: 4.3M
CGroup: /system.slice/nginx.service
├─3340 nginx: master process /usr/sbin/nginx -g daemon on; master_>
└─3341 nginx: worker process
Jul 29 07:21:52 chuan-server systemd[1]: Starting A high performance web server>
Jul 29 07:21:53 chuan-server systemd[1]: Started A high performance web server >
lines 1-13/13 (END)
如上所示,这个服务已经成功启动。接下来我们要直接来测试 Nginx 是否可以通过浏览器访问。
首先我们执行以下命令:
ip addr show eth0 | grep inet | awk '{ print $2; }' | sed 's/\/.*$//'
这可以让我们在浏览器中查看他们是否正常工作。
接着我们要找到服务器在公网上的ip,我们可以使用这个命令
curl -4 icanhazip.com
获得服务器ip后,我们可以在浏览器输入这个 ip 。当然除了公网,我们也可以输入主机的内网 ip 通过局域网来访问。