参考文档:https://blog.csdn.net/u013564742/article/details/81746335
零:要先安装依赖库
一、Nginx是一个web服务器也可以用来做负载均衡及反向代理使用,目前使用最多的就是负载均衡。
二、安装:
wget http://nginx.org/download/nginx-1.10.2.tar.gz
tar zxvf nginx-1.10.2.tar.gz
cd nginx-1.10.2
./configure && make && make install
三、启动
whereis nginx
cd /usr/local/nginx
sbin/nginx
ps -aux |grep nginx
展示如下,表示nginx 启动成功
root 12074 0.0 0.0 20536 608 ? Ss 16:02 0:00 nginx: master process sbin/nginx
nobody 12075 0.0 0.1 20980 1316 ? S 16:02 0:00 nginx: worker process
root 12080 0.0 0.0 112724 984 pts/0 R+ 16:02 0:00 grep --color=auto nginx
[root@localhost nginx]#
这样,在Linux上用curl访问IP地址,即可进入该服务器。
四、nginx基本操作:
启动
[root@localhost ~]# /usr/local/nginx/sbin/nginx
停止/重启
[root@localhost ~]# /usr/local/nginx/sbin/nginx -s stop(quit、reload)
命令帮助
[root@localhost ~]# /usr/local/nginx/sbin/nginx -h
验证配置文件
[root@localhost ~]# /usr/local/nginx/sbin/nginx -t
配置文件
[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf
五、开启外网访问
方法一直接关闭防火墙:
关闭防火墙
[root@localhost ~]# service iptables stop
关闭开机自启动防火墙
[root@localhost ~]# chkconfig iptables off
[root@localhost ~]# chkconfig --list|grep ipt
方法二将开启的端口加入防火墙白名单中
编辑防火墙白名单
[root@localhost ~]# vim /etc/sysconfig/iptables
增加下面一行代码
-A INPUT -p tcp -m state – state NEW -m tcp --dport 80 -j ACCEPT
保存退出,重启防火墙
[root@localhost ~]# service iptables restart
这样,在windows上访问IP地址,也可以访问了。
六、更改用户密码:
输入 echo "密码“ | passwd --stdin 用户名
关于Linux下Nginx服务启动,通过浏览器无法访问的问题
1.通过Linux查看Linux服务是否启动。
ps -aux |grep nginx
可以看到服务成功启动,但是在浏览器上还是无法访问。
2、Linux上检验:
curl http://192.168.195.129/
解决办法:
添加 80 段端口配置
firewall-cmd --zone=public --add-port=80/tcp --permanent
重启防火墙
systemctl restart firewalld.service