一. 安装nginx
1.yum安装nginx
(1)添加一个nginx的yum源
cd /etc/yum.repo.d #切换到yum安装源文件目录
vi nginx.repo #创建一个安装包源
把以下内容复制进去,保存退出
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/x86_64/
gpgcheck=0
enabled=1
(2)查看一下是否成功加载了这个安装源
yum repolist
(3)通过yum安装nginx
yum install nginx
(4)直接用systemctl启动nginx服务
systemctl enable nginx #设置nginx为开机启动
systemctl start nginx #启动nginx服务
(5)关闭防火墙
记得把防火墙关了 systemctl stop firewalld,输入服务器ip,发现ok了
2.编译安装nginx
(1)安装支持软件(依赖包)
root@localhost ~# yum -y install pcre* zlib* gcc*
(2)创建运行用户、组
Nginx 服务程序默认以 nobody 身份运行,建议为其创建专门的用户账号,以便更准确
地控制其访问权限,增加灵活性、降低安全风险。
root@localhost ~# useradd -M -s /sbin/nologin nginx
(3)编译安装 Nginx
启用 http_stub_status_module 模块以支持状态统计,便于查看服务器的连接信息。具
root@localhost ~# tar zxvf nginx-1.17.4.tar.gz
root@localhost ~# cd nginx-1.17.4/
root@localhost ~#./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http\_stub\_status\_module
root@localhost ~# make && make install
(4)创建软连接
root@localhost ~#ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
(5)检查配置文件
root@localhost ~# nginx -t ##检查nginx配置文件是否出错
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
(6)启动、停止 Nginx
root@localhost ~# nginx ##启动nginx
root@localhost ~# nginx -s stop ##停止nginx
root@localhost ~# nginx -s reload ##重载nginx
root@localhost ~# netstat -anpt | grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:\* LISTEN 20523/nginx: master
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。