引言
由于需要部署一个简历项目,属于纯静态页面,Nginx的处理效率要远高于Tomcat,所以找了很长时间的Nginx的安装教程,在这个软件的安装过程中只能说一把辛酸泪,十个人的教程就有十个人的方法,十个人的方法就会有九个安装错误、或者访问不了欢迎界面,真是跪了。
特此,博主总结一下我在安装软件的过程中使用到的一些方法,亲测安装成功,供大家参考使用。
准备
Centos7.3、阿里云服务器、域名、Xshell6、FileZilla
安装依赖(源码安装)
1、gcc安装: gccyyum -y install gcc-c++
2、pcre安装: yum -y install pcre pcre-devel
3、zlib安装: yum -y install zlib zlib-devel
4、openSSL安装:yum -y install openssl openssl-devel
Nginx安装
1、[官网下载](https://nginx.org/en/download.html)
2、选择FileZilla,将下载好压缩文件上传至服务器,自己指定目录,如博主的:
cd /usr/local/nginx,这个nginx是自己创建的,可以在可视化的FIleZilla中创,也可以在命令行:
mkdir /usr/local/nginx
3、在这个文件夹解压文件: tar -zxvf nginx-1.9.9.tar.gz,这里的nginx-1.9.9.tar.gz是压缩文件名。
4、静入安装目录 : cd /usr/local/nginx/nginx-1.9.9/
5、安装nginx: ./configue
6、执行 make
7、执行 make install
8、 查看版本:nginx -v
9、启动nginx: /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf ,启动方式很多种,别的也可启动,只要可以启动就行
10、测试配置文件nginx.conf正确性:/usr/local/nginx/nginx -t ,显示......syntax is ok......is successful
启动管理
root@localhost ~]# vim /etc/init.d/nginx
需要注意的配置:
nginx=”/usr/local/nginx/sbin/nginx” //修改成nginx执行程序的路径。
NGINX_CONF_FILE=”/usr/local/nginx/nginx-1.9.9/conf/nginx.conf” //修改成nginx.conf文件的路径。
保存后设置文件的执行权限:
[root@localhost ~]# chmod a+x /etc/init.d/nginx
至此就可以通过下面指令控制启动停止
/etc/init.d/nginx start
/etc/init.d/nginx stop
上面的方法完成了用脚本管理nginx服务的功能,但是还是不太方便。
先将nginx服务加入chkconfig管理列表:
[root@localhost ~]# chkconfig --add /etc/init.d/nginx
加完这个之后,就可以使用service对nginx进行启动,重启等操作了。
service nginx start
service nginx stop
service nginx restart
最后设置开机自动启动
[root@localhost ~]# chkconfig nginx on
更改默认端口
[root@nginx ~]# view /usr/local/nginx/conf/nginx.conf
考虑到apache的服务端口总是80,所以这里我们把它改成8090:
![在这里插入图片描述](https://img-blog.csdnimg.cn/20190916134708500.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQyMjg0NTA0,size_16,color_FFFFFF,t_70)
如图:80改成8090,localhost改成自己的域名
重新加载配置:
[root@nginx ~]# nginx -s reload
访问Nginx
1、关闭防火墙:
[root@nginx ~]# firewall-cmd --state
running
[root@nginx ~]# systemctl stop firewalld.service
[root@nginx ~]# firewall-cmd --state
not running
2、访问:本地浏览器打开 域名+ 8090
注意
如访问不了需要在阿里云服务器修改配置规则,具体上服务器修改开放8090端口