1、官网下载:
2、安装nginx需要的环境:
yum -y install gcc-c++
yum -y install -y pcre pcre-devel
yum -y install -y zlib zlib-devel
yum -y install -y openssl openssl-devel
yum -y install pcre-devel
yum -y install openssl openssl-devel
3、上传并解压:
/usr/local #上传至此目录
tar -zxvf nginx-1.18.0.tar.gz #解压
cd nginx-1.18.0/ #进入
mkdir /var/temp/nginx -p #先建个临时目录
4、编译:
在目录下运行此命令:
./configure \
--prefix=/usr/local/nginx \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/temp/nginx/client \
--http-proxy-temp-path=/var/temp/nginx/proxy \
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi
之后运行编译:
make
make install
至此可以看到nginx已经安装成功:
[root@instance-c38a6f8r nginx-1.18.0]# whereis nginx
nginx: /usr/local/nginx
目录介绍:
[root@instance-c38a6f8r nginx-1.18.0]# cd /usr/local/nginx
[root@instance-c38a6f8r nginx]# ll
total 12
drwxr-xr-x 2 root root 4096 May 15 00:30 conf #配置文件
drwxr-xr-x 2 root root 4096 May 15 00:30 html #静态资源文件夹
drwxr-xr-x 2 root root 4096 May 15 00:30 sbin #二进制文件,在此文件夹运行
5、运行Nginx:
[root@instance-c38a6f8r nginx]# cd sbin/
-rwxr-xr-x 1 root root 3883728 May 15 00:30 nginx #sbin只有一个nginx文件
[root@instance-c38a6f8r sbin]# ./nginx #运行
到这里就启动完成了,访问网站则会出现欢迎页
遇到问题的朋友可以留言,看到回复
常用的一些命令:
[root@instance-c38a6f8r sbin]# ./nginx #运行
[root@instance-c38a6f8r sbin]# ./nginx -s reload #重新加载
[root@instance-c38a6f8r sbin]# ./nginx -s quit #优雅的停止或者stop强行停止
[root@instance-c38a6f8r sbin]# ./nginx -t #检测nginx配置文件是否正确
[root@instance-c38a6f8r sbin]# ./nginx -v #查看当前版本
[root@instance-c38a6f8r sbin]# ./nginx -V #查看版本已经各种日志的配置路径
[root@instance-c38a6f8r sbin]# ./nginx -c filename #切换配置文件