第一步:我们要准备好VM虚拟机,现在有VM12Player版的是免费的自己去官方网站下载,有一两G的样子。
本次实验用的系统是centos6.5(linux)。
在开始之前,我们还要准备好nginx的压缩包:nginx-1.12.1.tar.gz
下载地址:http://download.csdn.net/download/muluo7fen/9960637(也可以去官网下载:http://nginx.org/en/download.html)

然后我们还要把网络共享一下,不然不能用yum安装。省的下载了。(没有网的话也可以去这里下载:)

打开虚拟机设置,

接着用右键打开“打开网络和共享中心”,就是在我们windows底部右边的连网图标,有可能隐藏起来了,点小箭号弹出隐藏的图标。


 
然后重启一下虚拟机,就可以连网了。
然后用root账户登录,不管有没界面,在终端或者ssh上面输入:#su root
回车输入密码完成登录
输入安装命令(3条):
#yum -y install zlib-devel
#yum install -y pcre pcre-devel
#yum install -y openssl openssl-devel
3个都装好了,就开始解压nginx-1.12.1.tar.gz
这里我把文件放在/home下,然后解压:#tar -zxf nginx-1.12.1.tar.gz

看到了把,右边的那个是我们的压缩文件,左边的是解压后的文件
然后我们进入解压后的文件#cd nginx-1.12.1
然后创建Nginx的用户组及用户
#groupadd nginx
#useradd -s /sbin/nologin -M -g nginx nginx
编译:
#./configure --user=nginx --group=nginx --prefix=/home/nginx-1.12.1 --conf-path=/home/nginx-1.12.1/nginx.conf --with-http_stub_status_module --with-http_ssl_module
如果在编译的时候发生如下问题:需要再次进行依赖安装:

#yum -y install gcc gcc-c++ autoconf automake make
安装:
#make && make install
配置:下面首字母是小写的L
#ln -s /home/nginx1.12.1/ /home/nginx
#echo 'PATH=/home/nginx-1.12.1/sbin:$PATH' >>/etc/profile
#source /etc/profile
最后启动:
#nginx -v
#/home/nginx/sbin/nginx -t
#/home/nginx/sbin/nginx
检查
#ps -ef |grep nginx
#netstat -antup |grep 80
这里我们就可以看到

80端口已经打开了,红线的部分是虚拟机的ip我们使用默认配置是不能让其他局域网的机器访问当前机子上的虚拟机网络,只有本地可以。
先打开浏览器验证一下:

出现这个界面就说明成功了,上面的ip地址其实是省略了:80端口,不输也是可以的
我们再配置一下,让其他电脑也可以访问这个虚拟机上的nginx。

接下来要配置反向代理和tomcat集群了,在下一篇文章再记录,先去动手了。 |