Nginx 在Centos7系统上的安装步骤
卸载
1 2 3 4 5 6 7 8 9 10 11
| service nginx stop
chkconfig nginx off
rm -rf /usr/sbin/nginx rm -rf /etc/nginx rm -rf /etc/init.d/nginx rm -rf /usr/local/nginx
yum remove nginx
|
软件包安装
本方法参照官方文档
先决条件
1
| sudo yum install yum-utils
|
添加Nginx的yum仓库
添加/etc/yum.repos.d/nginx.repo
文件,内容如下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| [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
|
安装
启动
检查
1
| netstat -lnpt | grep nginx
|
源码构建安装
下载源码
去官方下载地址 稳定版本源码并上传到服务器
也可以使用wget 下载 wget https://nginx.org/download/nginx-1.18.0.tar.gz
解压
1
| tar -xvf nginx-1.18.0.tar.gz
|
先决条件
1
| yum -y install gcc gcc-c++ automake zlib zlib-devel openssl openssl--devel pcre pcre-devel
|
编译与安装
以下操作必须要在nginx源码解压后的文件夹下操作
1 2 3 4 5 6
| ./configure
make
make install
|
启动
1
| /usr/local/nginx/sbin/nginx
|
检查
1
| netstat -lnpt | grep nginx
|
Docker-Compose安装
1 2 3 4 5 6 7 8 9 10 11 12 13
| version: '3' services: nginx: image: nginx:latest restart: always ports: - 80:80 - 443:443 volumes: - ./conf.d:/etc/nginx/conf.d - ./_log:/var/log/nginx - ./www:/var/www - /etc/letsencrypt:/etc/letsencrypt
|