ubuntu下可以直接使用apt install nginx来安装
安装完成后,检查Nginx服务的状态和版本
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: en
Active: active (running) since Sat 2019-05-11 21:17:07 CST; 25s ago
Docs: man:nginx(8)
Process: 29483 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (cod
Process: 29473 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process
Main PID: 29485 (nginx)
Tasks: 5 (limit: 4915)
CGroup: /system.slice/nginx.service
├─29485 nginx: master process /usr/sbin/nginx -g daemon on; master_pr
├─29487 nginx: worker process
├─29489 nginx: worker process
├─29492 nginx: worker process
└─29493 nginx: worker process
5月 11 21:17:07 zhf-maple systemd[1]: Starting A high performance web server and
5月 11 21:17:07 zhf-maple systemd[1]: Started A high performance web server and
...skipping...
● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: en
Active: active (running) since Sat 2019-05-11 21:17:07 CST; 25s ago
Docs: man:nginx(8)
Process: 29483 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (cod
Process: 29473 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process
Main PID: 29485 (nginx)
Tasks: 5 (limit: 4915)
CGroup: /system.slice/nginx.service
├─29485 nginx: master process /usr/sbin/nginx -g daemon on; master_pr
├─29487 nginx: worker process
├─29489 nginx: worker process
├─29492 nginx: worker process
└─29493 nginx: worker process
5月 11 21:17:07 zhf-maple systemd[1]: Starting A high performance web server and
5月 11 21:17:07 zhf-maple systemd[1]: Started A high performance web server and
查看nginx的版本:
nginx -v
nginx version: nginx/1.14.0 (Ubuntu)
如果您正在运行防火墙,则还需要打开端口80和443。
sudo ufw allow ‘Nginx Full‘
以下方式验证更改:
ufw
status
[sudo] linuxidc 的密码:
输出:
状态: 激活
至
动作
来自
-
-- --
Nginx
Full ALLOW
Anywhere
Nginx Full (v6)
ALLOW Anywhere (v6)
此时在浏览器中输入IP地址比如本地IP地址localhost。看到页面如下,表示Nginx已经启动成功
你可以像任何其他systemd单位一样管理Nginx服务。 要停止Nginx服务,请运行:
sudo systemctl stop nginx
要再次启动,请键入:
sudo systemctl start nginx
重新启动Nginx服务:
sudo systemctl restart nginx
在进行一些配置更改后重新加载Nginx服务:
$sudo systemctl reload nginx
如果你想禁用Nginx服务在启动时启动:
$sudo systemctl disable nginx
并重新启用它:
$sudo systemctl enable nginx
原文:https://www.cnblogs.com/zhanghongfeng/p/10850176.html