nginx学习(二)
访问nginx的官方网站:http://www.nginx.org/
nginx版本类型:
- Mainline version: 主线版,即开发版
- Stable version: 最新稳定版,生产环境上建议使用的版本
- Legacy versions: 遗留的老版本的稳定版
nginx的安装(yum安装)
- 使用默认的yum仓库,epel仓库里是有关于nginx的yum仓库 确保你的服务器上有epel扩展仓库,并且要保证你的服务器网络正常,yum仓库正常 如果有epel仓库,其他都正常:yum -y install nginx如果没有epel仓库,其他都正常,安装epel仓库,在去安装nginx。
- 使用官方的yum仓库。
配置Yum源的官网:
http://nginx.org/en/linux_packages.html
- 配置nginx YUM源
vim /etc/yum.repos.d/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
- 安装
yum install nginx -y(安装最新的稳定版本)
- 查看版本
nginx -v 查看nginx的版本
nginx -V //可以查看它的参数 格式化打印
- 关闭防火墙和selinux
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
- 启动nginx
systemctl start nginx
systemctl enable nginx (开机自启)
- 访问网站
nginx的安装(编译安装)
- 安装编译环境
yum -y install gcc gcc-c++ make ncurses ncurses-devel
- 安装pcre软件包(使nginx支持http rewrite模块)
yum install -y pcre pcre-devel
- 安装openssl-devel(使nginx支持ssl)
yum install -y openssl openssl-devel
- 安装zlib
yum install -y zlib zlib-devel
- 创建用户nginx
useradd nginx
- 安装nginx
wget http://nginx.org/download/nginx-1.18.0.tar.gz
tar xf nginx-1.18.0.tar.gz -C /usr/local/
cd /usr/local/nginx-1.18.0/
./configure --prefix=/usr/local/nginx --group=nginx --user=nginx --sbin-path=/usr/local/nginx/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/tmp/nginx/client_body --http-proxy-temp-path=/tmp/nginx/proxy --http-fastcgi-temp-path=/tmp/nginx/fastcgi --pid-path=/var/run/nginx.pid --lock-path=/var/lock/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-pcre --with-http_realip_module --with-stream
make && make install(编译安装)
- 启动nginx
[root@localhost sbin]# pwd
/usr/local/nginx/sbin
[root@localhost sbin]# ./nginx
如果启动出现下列问题:
nginx: [emerg] mkdir() "/tmp/nginx/client_body" failed (2: No such file or directory)
解决方案:
[root@localhost sbin]# mkdir -pv /tmp/nginx/client_body
然后再次启动
[root@localhost sbin]# ./nginx
- 总结:
编译安装过程:(定制)
1.安装编译安装所需要的环境(软件包,创建用户)
2.下载编译安装所需要的包(源码包)解压的操作
3.到解压后的目录下进行配置(./configure 配置所需要的参数)【mysql:cmake进行配置】
4.编译 make
5.安装 make install