本文将为大家介绍在CentOS7系统下安装Nginx的两种方式。
一、编译安装
1. 安装编译安装所需要的依赖
yum install -y gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel
2.下载Nginx
1 2 3 |
yum install -y wget wget https://nginx.org/download/nginx-1.14.0.tar.gz |
3. 解压
1 2 3 |
tar zxf nginx-1.14.0.tar.gz cd nginx-1.14.0 |
4. 编译安装(默认设置)
1 2 3 |
./configure make && make install |
5. 查看安装目录
1 2 3 |
whereis nginx nginx: /usr/local/nginx |
启动Nginx
1 2 3 |
cd /usr/local/nginx/sbin ./nginx |
7. 查看Nginx是否运行
1 2 3 4 |
ps -ef | grep -v grep | grep nginx root 4772 1 0 18:27 ? 00:00:00 nginx: master process ./nginx nobody 4773 4772 0 18:27 ? 00:00:00 nginx: worker process |
8. 查看Nginx默认监听端口
vi /usr/local/nginx/conf/nginx.conf
注意:对于编译安装来说,任何对于Nginx配置文件的修改,如想使其生效,必须重载Nginx,使用以下命令:
./nginx -s reload
二、yum安装
1. 安装
yum install -y nginx
2. 启动Nginx并设置开机启动
1 2 3 |
systemctl start nginx systemctl enable nginx |
3. 验证Nginx是否启动
1 2 3 4 |
ps -ef | grep -v grep | grep nginx root 2195 1 0 20:25 ? 00:00:00 nginx: master process /usr/sbin/nginx nginx 2196 2195 0 20:25 ? 00:00:00 nginx: worker process |
4. 查看Nginx配置文件
vi /etc/nginx/nginx.conf
5. 对于yum安装的Nginx来说,要想使配置文件的修改生效,需要重启Nginx,运行以下命令:
systemctl restart nginx
6. 网页验证Nginx是否成功运行。
注意:Nginx默认的监听端口为80,滴滴云EIP的80端口只有在完成备案后才可以访问,有关备案的知识请参考备案流程。