nginx下载地址: http://nginx.org/en/download.html

01、下载安装

wget http://nginx.org/download/nginx-1.20.1.tar.gz

02、安装编译工具及库文件

yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel

03、解压nginx

tar -zxvf nginx-1.20.1.tar.gz

04、创建nginx的临时目录

mkdir -p /var/temp/nginx

05、进入安装包目录

cd nginx-1.20.1

06、编译安装

./configure \
--prefix=/usr/local/nginx \
--pid-path=/var/run/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/fastgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-http_stub_status_module

安装以后的目录信息

  1. nginx path prefix: "/usr/local/nginx" nginx binary file: "/usr/local/nginx/sbin/nginx" nginx modules path: "/usr/local/nginx/modules" nginx configuration prefix: "/usr/local/nginx/conf" nginx configuration file: "/usr/local/nginx/conf/nginx.conf" nginx pid file: "/var/run/nginx.pid" nginx error log file: "/var/log/nginx/error.log" nginx http access log file: "/var/log/nginx/access.log" nginx http client request body temporary files: "/var/temp/nginx/client" nginx http proxy temporary files: "/var/temp/nginx/proxy" nginx http fastcgi temporary files: "/var/temp/nginx/fastgi" nginx http uwsgi temporary files: "/var/temp/nginx/uwsgi" nginx http scgi temporary files: "/var/temp/nginx/scgi"

07、 make编译

make

08、 安装

make install

9、 进入sbin目录启动nginx

cd /usr/local/nginx/sbin

10、执行nginx启动

./nginx

#停止:

./nginx -s stop

#重新加载:

./nginx -s reload

11、打开浏览器,访问虚拟机所处内网ip即可打开nginx默认页面,显示如下便表示安装成功:

welcome to nginx

12、注意事项

  1. 如果在云服务器安装,需要开启默认的nginx端口:80

  2. 如果在虚拟机安装,需要关闭防火墙

  3. 本地win或mac需要关闭防火墙

  4. nginx的安装目录是:/usr/local/nginx/sbin

13、配置nginx的环境变量

vim /etc/profile

在文件的尾部追加如下:

export NGINX_HOME=/usr/local/nginx
export PATH=$NGINX_HOME/sbin:$PATH

重启配置文件

source /etc/profile