简介:使用nginx源码包,安装nginx服务器,并对其进行配置后,测试其成果。
模仿百度主页!
第一步:检查依赖关系
[[email protected] ~]# rpm -q zlib-devel pcre-devel
package zlib-devel is not installed
package pcre-devel is not installed
[[email protected] ~]# ls /mnt/Packages/*zlib*
/mnt/Packages/zlib-1.2.7-15.el7.i686.rpm /mnt/Packages/zlib-devel-1.2.7-15.el7.i686.rpm
/mnt/Packages/zlib-1.2.7-15.el7.x86_64.rpm /mnt/Packages/zlib-devel-1.2.7-15.el7.x86_64.rpm
[[email protected] ~]# ls /mnt/Packages/*pcre-devel*
/mnt/Packages/pcre-devel-8.32-15.el7.i686.rpm /mnt/Packages/pcre-devel-8.32-15.el7.x86_64.rpm
[[email protected] ~]# rpm -ivh /mnt/Packages/zlib-devel-1.2.7-15.el7.x86_64.rpm
warning: /mnt/Packages/zlib-devel-1.2.7-15.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:zlib-devel-1.2.7-15.el7 ################################# [100%]
[[email protected] ~]# rpm -ivh /mnt/Packages/pcre-devel-8.32-15.el7.x86_64.rpm
warning: /mnt/Packages/pcre-devel-8.32-15.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:pcre-devel-8.32-15.el7 ################################# [100%]
第二步:创建nginx用户,不创建宿主目录-M,指定不能登录 -s /sbin/nologin
[[email protected] ~]# useradd nginx -M -s /sbin/nologin
useradd: cannot open /etc/passwd
[[email protected] ~]# lsattr /etc/passwd
----i----------- /etc/passwd
[[email protected] ~]# chattr -i /etc/passwd
[[email protected] ~]# useradd nginx -M -s /sbin/nologin
[[email protected] ~]# tail -1 /etc/passwd
nginx:x:1001:1001::/home/nginx:/sbin/nologin
[[email protected] ~]# ls /home/
gan
第三步:解压nginx源码包
(下载nginx源码包,并通过xmanager上传到linux虚拟机中--->此处省略)
[[email protected] ~]# tar zxf nginx-1.11.2.tar.gz -C /usr/src
[[email protected] ~]# ls /usr/src/nginx-1.11.2
auto CHANGES CHANGES.ru conf configure contrib html LICENSE man README src
第四步:配置安装文件
[[email protected] ~]# cd /usr/src/nginx-1.11.2/
[[email protected] nginx-1.11.2]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx
###########此处省略##############
[[email protected] nginx-1.11.2]# echo $?
0
第五步:生成配置文件
[[email protected] nginx-1.11.2]# make -j 4
[[email protected] nginx-1.11.2]# echo $?
0
第六步:make install安装
[[email protected] nginx-1.11.2]# make install
###########此处省略##############
第七步:优化启动脚本
[[email protected] nginx-1.11.2]# cp /usr/local/nginx/sbin/nginx /usr/sbin
[[email protected] nginx-1.11.2]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
#注释:nginx -t 测试nginx服务
第八步:启动nginx并验证
[[email protected] nginx-1.11.2]# nginx
[[email protected] nginx-1.11.2]# netstat -anlpt | grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 8540/nginx: master
[[email protected] nginx-1.11.2]#
使用宿主机,登录虚拟机IP看一下,OK,见到下面的情况说明已经搭建成功了!!!
模仿:<注释:仅做为实验教程,请不要进行其他恶意破坏>
第一步:进入某站主页,右键查看源
第二步:ctrl + a 然后,右键,复制
第三步:在桌面新建一个文本文档,将复制的内容ctrl + v拷贝上去,然后另存为index.html
第四步:使用xmanager将新建的index.html文件上传的虚拟机中,然后将其拷贝到/usr/local/nginx/html/.下
第五步:使用宿主机进入虚拟机ip查看,OK,成功了