Linux启动Nginx服务的步骤:
要素 1:安装 Nginx
- 使用包管理器安装 Nginx:
- Debian/Ubuntu:sudo apt-get install nginx
- Red Hat/CentOS:sudo yum install nginx
要素 2:启动 Nginx
- 启动 Nginx 服务:
- Systemd(大部分现代 Linux 发行版):sudo systemctl start nginx
- SysV init(较旧的 Linux 发行版):sudo service nginx start
要素 3:验证 Nginx 状态
- 查看 Nginx 状态:
- Systemd:sudo systemctl status nginx
- SysV init:sudo service nginx status
要素 4:启用 Nginx 自启动
- 设置 Nginx 在系统启动时自启动:
- Systemd:sudo systemctl enable nginx
- SysV init:sudo chkconfig nginx on
要素 5:检查 Nginx 端口
- 默认情况下,Nginx 监听 TCP 端口 80:
- 使用 netstat 命令验证:sudo netstat -anp | grep nginx
要素 6:访问 Nginx 默认页面
- 在浏览器中访问 Nginx 默认页面(http://localhost):
- 如果显示 "Welcome to nginx!" 则表示 Nginx 已成功启动。