0
点赞
收藏
分享

微信扫一扫

linux在线安装 nginx

sudo yum install nginx

启动nginx
[root@localhost ~] sudo service nginx start
Redirecting to /bin/systemctl start nginx.service
[root@localhost ~] netstat -ntlp | grep 80   // 没有netstat自己安装下 sudo yum install net-tools
tcp  0  0 0.0.0.0:80  0.0.0.0:*   LISTEN  1589/nginx: master  // nginx服务启动,并且监听在80端口
自启动:systemctl enable nginx.service

测试
在自己的电脑输入 http://ip:80, 出现以下界面则说明安装成功
如果出现了访问失败,则需要在访问的电脑中进行如下检测


telnet 192.168.0.101 80  // 查看nginx服务器的80端口能不能访问。

如果不能访问80端,查看服务器 selinux和firewall 是否开启了
[root@localhost ~] sudo getenforce  // 查看selinux是否开启
enforcing                  // enforecing 则未开启了
[root@localhost ~] vi /etc/selinux/config  // 永久关闭selinux,打开/etc/selinux/config编辑

SELINUX = disabled   // 将 SELINUX = enforcing 改为 disabled

可以重启服务器生效。
给firewalld 添加 80 端口
[root@localhost ~] sudo systemctl status firewalld    // 查看firewalld是否开启了
firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
   Active: active (running) since Sun 2019-12-15 23:57:33 CST; 4min 36s ago
     Docs: man:firewalld(1)
 Main PID: 824 (firewalld)
    Tasks: 2 (limit: 4912)
   Memory: 35.4M
   CGroup: /system.slice/firewalld.service
           └─824 /usr/libexec/platform-python -s /usr/sbin/firewalld --nofork --nopid

12月 15 23:57:32 localhost.localdomain systemd[1]: Starting firewalld - dynamic firewall daemon...
12月 15 23:57:33 localhost.localdomain systemd[1]: Started firewalld - dynamic firewall daemon.

出现了上面的说明firewalld已经开启了。
[root@localhost ~] sudo firewall-cmd --zone=public --add-port=80/tcp --permanent  //添加80端口
success
[root@localhost ~] sudo systemctl restart firewalld  // 重启下firewalld

继续测试,应该可以访问成功了。

举报

相关推荐

0 条评论