1. Entry-level deployment

Learn more about automated deployment

1. Implementation brief

  1. Download the stable version of nginx from nginx’s official website.
  2. Upload the zip package to /usr/local, decompress, configure, compile, and generate an executable file.
  3. Nginx configuration file configuration, start

2. Preparation

Before installing nginx, check whether g++, GCC, openssl-devel, pcre-devel and zlib-devel are installed on the system.

1-1. Description of these dependency packages

  1. Installing nginx requires compiling the nginx source code, which depends on the GCC environment.
  2. PCRE(Perl Compatible Regular Expressions) is a Perl library that includes the Perl-compatible Regular expression library. The HTTP module of Nginx uses PCRE to parse regular expressions, so you need to install the PCRE library on Linux. Pcre-devel is a secondary development library developed using PCRE.
  3. The Zlib library provides a variety of compression and decompression methods. Nginx uses Zlib to gzip the contents of HTTP packages.
  4. OpenSSL is a powerful Secure Socket layer cryptographic library that includes major cryptographic algorithms, common key and certificate encapsulation management capabilities, and SSL protocols, and provides rich applications for testing and other purposes. Nginx supports not only HTTP but also HTTPS (that is, HTTP over SSL)

1-2. Check whether the command is installed

Yum list installed | grep GCC / / this instruction can check GCC can check again the g + + yum list installed | grep openssl devel - yum list installed | grep pcre-devel yum list installed | grep zlib-develCopy the code

If it is installed, it will have the corresponding information

1-3. Install dependencies

yum install gcc-c++ yum install -y pcre pcre-devel yum install -y zlib zlib-devel yum install -y openssl openssl-devel # yum install unzip # yum install unzip # yum install unzipCopy the code

3. Decompress, compile, and generate an execution file

3-1. Upload and decompress

Upload to /usr/local/, or anywhere else. Upload operation on MAC

SCP dist. Zip root@[server address]/usr/localCopy the code

Default root is the user name, login Ali cloud server instance can see your server address. Then unpack

Tar -zxvf [nginx package name, suffix]Copy the code

3-2. Compile and generate an execution file

Create an nginx folder to store the generated execution files

mkdir nginx
Copy the code

Then go into the decompressed nginx package and execute some commands to generate the execution file

1) Configuration commands
./configure --prefix=/usr/local/nginx
Copy the code

The Configure script is responsible for preparing the build environment for the software on the system you use. Make sure you have the dependencies you need for the rest of the build and installation process, and figure out what you need to use them.

Unix programs are generally written in C, so we usually need a C compiler to build them. In this example, all Configure does is make sure the C compiler is on the system, and determine its name and path.

2) compilation
make
Copy the code

When configure is configured, you can use the make command to perform the build. This process performs a series of tasks defined in a Makefile to compile the software source code into an executable. Instead of a final Makefile, you download a template file called makefile. in and configure generates a customized Makefile based on the system’s parameters.

3) Write the execution file
make install
Copy the code

Write the generated files to the folder specified by the./configure command

See this article for more configuration and compilation instructionsConfigure, make, make install

4. Nginx startup and configuration

4-1. Start the nginx server

Enter/usr/local/nginx/sbin /

Start the
./nginx
Copy the code
restart

After modifying the configuration file, restart it

./nginx -s reload
Copy the code
stop
./nginx -s stop
Copy the code
Check whether the startup is successful

No prompt is the best prompt, no prompt generally indicates that the success, you can also use the following command to view

ps -ef|grep nginx
Copy the code

After startup, enter the address of your Aliyun server and the browser will return you with a successful nginx interface, which is the default index.html interface in the configuration file

4 – (2) nginx configuration

Enter/usr/local/nginx/conf /

Specify the root directory as your project

Vi Open the nginx.conf configuration file and type I on the keyboard. There is –INSERT– below the window, indicating that you are ready to edit, and then move the keyboard up, down, left and right. Press Esc to exit the edit (exit INSERT state), then :wq to save the edit and exit

sever { listen 80; localtion / { root dist; index index.html; }}Copy the code

My front-end package is in DIST, and I can open the project by typing in the server address in the browser.