Nginx安装
基本环境配置
1.切换用户到root用户
2.把安装的文件复制到linux上
3.在/目录下创建文件夹/data/server,/data/soft
命令: mkdir /data/{server,soft} -p
4.移动复制在linux上的文件到soft目录下
命令:mv /root/Desktop/* /data/soft
nginx安装
1.创建一个nginx专用用户
useradd www -s /sbin/nologin -M
2.编译安装ngnix
(1)进入 目录cd /data/soft
(2)解压 tar xzf nginx-1.10.2.tar.gz
(3)进入 cd nginx-1.10.2
(4)安装 ./configure --prefix=/data/server/nginx
注意:按照视频安装可能会报错
第一个错
[root@localhost nginx-1.10.2]# ./configure
checking for OS
+ Linux 2.6.32-642.el6.x86_64 x86_64
checking for C compiler ... not found
./configure: error: C compiler cc is not found
解决:yum -y install gcc
yum -y install gcc-c++
第二个错
./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=<path> option.
解决:yum -y install openssl openssl-devel
yum -y install pcre-devel
(5)编译 make
(6)make install
修改配置文件
1。gedit /data/server/nginx/conf/nginx.conf
修改 user www;
检查运行
1.启动ngnix
进入目录:cd /data/server/nginx/sbin
执行: ./nginx
2.浏览器/命令检查是否启动
(1)浏览器检查
浏览器直接打开localhost
(2)命令检查是否启动
netstat -tnulp 查看所有端口
netstat -tnulp | grep nginx 查看nginx的端口
ifconfig 查看linux的网络
本地打不开虚拟机的80端口,需要设置虚拟机的网络防火墙
vi /etc/sysconfig/iptables
-A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT(允许80端口通过防火墙)
重启防火墙
/etc/init.d/iptables restart
ngnix简单操作
检查 ./nginx -t
启动 ./nginx
关闭 ./nginx -s stop
重启 ./ngnix -s reload
检查 netstat -tnulp | grep nginx