Table of contents
Installation steps under Liunx
Supplement: Docker install nginx
Version introduction
-
Nginx open source version http://nginx.org/en/
Official original Nginx version
-
Nginx plus commercial version
Works right out of the box with tons of integrated features
-
Open Resty https://openresty.org/cn/
OpenResty is a high-performance web platform based on Nginx and Lua. It integrates a large number of sophisticated Lua libraries, third-party modules and most dependencies. It is more suitable for scenarios that require a large amount of secondary development and has strong scalability.
-
Tengine https://tengine.taobao.org/
A web server project initiated by Taobao. Based on Nginx (opens new window) , it adds many advanced functions and features to meet the needs of large-traffic websites. The performance and stability of Tengine have been well tested on large websites such as Taobao (opens new window) , Tmall Mall (opens new window), etc. Compared with Open Resty, the scalability is not strong enough, but it can meet the vast majority of usage scenarios.
Installation steps under Liunx
Download Nginx package
Download it to Windows first and then transfer it to the Linux virtual machine.
Switch to the path of the installation package, unzip the Nginx package, and install it
tar -zxvf nginx-1.25.2.tar.gz #解压到当前目录
cd nginx-1.25.2 #进入解压后的文件夹
ls #文件夹中的文件:auto CHANGES.ru configure html man src CHANGES conf contrib LICENSE README
Install dependent libraries
#安装C编译器
yum install -y gcc
#安装pcre库
yum install -y pcre pcre-devel
#安装zlib
yum install -y zlib zlib-devel
Install
./configure --prefix=/usr/local/nginx #使用prefix选项指定安装的目录
make
make install
start up
cd /usr/local/nginx/sbin
ls # 里面是一个nginx的可执行文件
./nginx # 启动这个可执行
Turn off firewall
systemctl stop firewalld
Enter the corresponding IP address in the browser
http://192.168.107.137/
The above are all the installation steps.
Supplement: Docker install nginx
Download Nginx image
Order | describe |
---|---|
docker pull nginx | Download the latest version of Nginx image (in fact, this command is equivalent to: docker pull nginx:latest) |
docker pull nginx:xxx | Download the Nginx image of the specified version (xxx refers to the specific version number) |
Create Nginx configuration file
Before starting, you need to create the Nginx externally mounted configuration file (/home/nginx/conf/nginx.conf). The
reason why it needs to be created first is because the Nginx container only exists in the /etc/nginx directory, and nginx.conf itself is not created. documentWhen the nginx.conf file does not exist on the server or container, docker will create nginx.conf as a directory when executing the startup command. This is not the result we want.
# 创建挂载目录
mkdir -p /home/nginx/conf
mkdir -p /home/nginx/log
mkdir -p /home/nginx/html
# 生成容器
docker run --name nginx -p 9001:80 -d nginx
# 将容器nginx.conf文件复制到宿主机
docker cp nginx:/etc/nginx/nginx.conf /home/nginx/conf/nginx.conf
# 将容器conf.d文件夹下内容复制到宿主机
docker cp nginx:/etc/nginx/conf.d /home/nginx/conf/conf.d
# 将容器中的html文件夹复制到宿主机
docker cp nginx:/usr/share/nginx/html /home/nginx/
Create Nginx container and run
docker run \
-p 9002:80 \
--name nginx \
-v /home/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \
-v /home/nginx/conf/conf.d:/etc/nginx/conf.d \
-v /home/nginx/log:/var/log/nginx \
-v /home/nginx/html:/usr/share/nginx/html \
-d nginx:latest
Command Description
–name nginx starts the name of the container
-d runs in the background
-p 9002:80 Maps the container’s 9002 (the latter) port to the host’s 80 (the former) port
-v /home/nginx/conf/nginx.conf: /etc/nginx/nginx.conf mount nginx.conf configuration file
-v /home/nginx/conf/conf.d:/etc/nginx/conf.d mount nginx configuration file
-v /home/nginx/log: /var/log/nginx Mount nginx log file
-v /home/nginx/html:/usr/share/nginx/html Mount nginx content
nginx:latest locally running version
\ shell command line break