linux安装nginx,关闭防火墙,本地访问及遇到的坑记录
进入/home/leyou目录
rz上传tar.gz文件到/home/leyou目录,ll查看文件
解压文件:tar xvf nginx.tar.gz
删除压缩包:rm -rf nginx.tar.gz
进入解压文件.cd nginx
指定安装目录:
./configure --prefix=/opt/nginx --sbin-path=/usr/bin/nginx
报错1 :
checking for C compiler ... not found
缺少c环境:
安装:
cd ~
yum -y install gcc
yum -y install gcc-c++
报错2:
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre= option.
yum -y install openssl openssl-devel
重新进入nginx解压文件目录下
cd /home/leyou/nginx/
再重新执行指定安装目录
./configure --prefix=/opt/nginx --sbin-path=/usr/bin/nginx
成功后编译和安装:
make && make install
查看进程:
ps -ef|grep nginx
此时还没有启动nginx,
启动nginx:nginx
再次查看进程:
ps -ef|grep nginx
多了两行:
master process:为主进程,主要用于监控和管理
work:处理用户请求
问题:如果查询不到这两个进程,很有可能是端口被占用,启动失败,则需要关闭防火墙或者该端口等操作配置
关闭防火墙:service iptables stop 临时关闭
或者开机禁用防火墙:
chkconfig iptables off
设置后重启下配置 就生效了
临时关闭防火墙报错:
Redirecting to /bin/systemctl stop iptables.service
Failed to stop iptables.service: Unit iptables.s
安装:使用systemctl
yum install iptables-services
systemctl enable iptables.service //设置开机启动
vim安装:
先查询是否安装:
rpm -qa|grep vim
都没有安装,执行安装:
命令: yum -y install vim*
关于linux上安装nginx,本地浏览器通过虚拟机ip无法访问到的问题:
CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙。
第一步:
关闭firewall:
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动
//firewall-cmd –state #查看默认防火墙状态(关闭后显示notrunning,开启后显示running)
第二步:
更改iptables防火墙配置:
进入配置文件: vim /etc/sysconfig/iptables
添加:
-A INPUT -p tcp -m state –state NEW -m tcp –dport 80 -jACCEPT
-A INPUT -p tcp -m state –state NEW -m tcp –dport 8080-j ACCEPT
意思指放行端口:80和8080
然后保存退出:按esc 输入“:wq”
重启iptables:
service iptables restart
再次访问:
成功!