侧边栏壁纸
  • 累计撰写 13 篇文章
  • 累计创建 10 个标签
  • 累计收到 4 条评论

目 录CONTENT

文章目录

在centos7.x上安装配置nginx

Jhl
Jhl
2023-09-13 / 0 评论 / 0 点赞 / 35 阅读 / 6106 字 / 正在检测是否收录...

第一种方法:

1. 安装前准备:

[root@ljh99.cn ~]# yum install yum-utils

yum-utils功能简介:管理repository及扩展包的工具 (主要是针对repository)

2. 添加源

[root@ljh99.cn ~]# cd /etc/yum.repos.d/
[root@ljh99.cn ~]# vim nginx.repo
[root@ljh99.cn ~]# cat nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
[root@ljh99.cn ~]#

3. 安装Nginx

[root@ljh99.cn ~]# yum makecache              #重建yum数据缓存已建立
[root@ljh99.cn ~]# yum install nginx -y       #安装nginx
[root@ljh99.cn ~]# rpm -qa | grep nginx       #安装完后,查看是否安装成功
[root@ljh99.cn ~]# systemctl start nginx      #启动nginx
[root@ljh99.cn ~]# systemctl enable nginx     #设置开机自启
[root@ljh99.cn ~]# systemctl status nginx     #查看nginx的状态. 测试是否可以正常访问Nginx

4. 测试是否可以正常访问Nginx

centos nginx_install.png

第二种方法:

1. 安装依赖包

  [root@ljh99.cn ~]# yum -y install gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel pcre pcre-devel gd-*

2. 创建用户

[root@ljh99.cn ~]# useradd -s /sbin/nologin nginx  
#不允许该用户登录

3. 下载nginx-1.18.0源码包

[root@ljh99.cn ~]# cd /usr/local/src
[root@ljh99.cn src]# wget http://nginx.org/download/nginx-1.18.0.tar.gz 
-bash: /usr/bin/wget: 没有那个文件或目录
#使用wget提示这个上面的信息,先安装wget 命令:yum -y install wget  安装完成再重新执行上面的命令

4. 解压nginx

[root@ljh99.cn src]# tar -zxvf nginx-1.18.0.tar.gz

5. nginx设置安装目录和启用的模块

[root@ljh99.cn src]# mkdir -p /usr/local/nginx
[root@ljh99.cn src]# cd nginx-1.18.0/
[root@ljh99.cn nginx-1.18.0]# ls
auto  CHANGES  CHANGES.ru  conf  configure  contrib  html  LICENSE  man  README  src
[root@ljh99.cn nginx-1.18.0]# ./configure \
--prefix=/usr/local/nginx \
--lock-path=/usr/local/nginx/nginx.lock \
--user=nginx \
--group=nginx \
--with-http_ssl_module --with-http_flv_module \
--with-http_stub_status_module --with-http_gzip_static_module \
--http-client-body-temp-path=/usr/local/nginx/client/ \
--http-proxy-temp-path=/usr/local/nginx/proxy/ \
--http-fastcgi-temp-path=/usr/local/nginx/fcgi/ \
--http-uwsgi-temp-path=/usr/local/nginx/uwsgi \
--http-scgi-temp-path=/usr/local/nginx/scgi --with-pcre \
--with-file-aio --with-http_image_filter_module

6. 编译

[root@ljh99.cn nginx-1.18.0]# make      #编译的过程有点慢

7. 安装

[root@ljh99.cn nginx-1.18.0]# make install

8. 启动

#启动方式-1
[root@ljh99 nginx-1.18.0]# cd /usr/local/nginx
[root@ljh99 nginx]# ls
client  conf  fcgi  html  logs  proxy  sbin  scgi  uwsgi
[root@ljh99 nginx]# sbin/nginx              # 启动服务 
#关闭服务              /usr/local/nginx/sbin/nginx -s stop      
#重新加载配置文件       /usr/local/nginx/sbin/nginx -s reload    
#查看编译选项          /usr/local/nginx/sbin/nginx -t
#测试配置文件          /usr/local/nginx/sbin/nginx -v
#查看版本信息          /usr/local/nginx/sbin/nginx -V
#启动方式-2
[root@ljh99 nginx-1.18.0]# ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx      #创建一个nginx软链接
[root@ljh99 nginx-1.18.0]# nginx 			
#启动服务(如需开机自启,可在/etc/rc.d/rc.local 文件中添此命令) 
#如出现:nginx: [error] invalid PID number "" in "/usr/local/nginx/logs/nginx.pid" 则需通过nginx –c /usr/local/nginx/conf/nginx.conf    命令指定nginx配置所在位置

9. 测试是否可以正常访问Nginx

centos nginx_install.png

0

评论区