Nginx installation

Software Installation

There are many ways to install the same software. In Linux, there are several common ways to install software:

1, source code compilation and installation: generally need to decompress and then use make, make install and other commands, this way the steps are more complex, the compilation time is long, and the results are not controllable

RedHat Package Manager (RPM) is a software management Package that makes installing and uninstalling easy, but does not resolve dependencies between packages

YUM (Yellow Dog Updater, Modified) is an RPM front-end program that automatically resolves software dependencies. Be aware of version issues, however, as the default installation from the repository is not necessarily the latest version

4, do not need to install as long as the configuration environment variables (decompression can be used)

download

Address from nginx.org/en/download… copy

CD/usr/local/soft wget HTTP: / / http://nginx.org/download/nginx-1.18.0.tar.gzCopy the code

Unpack the

The tar - XZVF nginx - 1.18.0. Tar. GzCopy the code

Installing a dependent Environment

GCC environment: the basic running environment

Pcre: The HTTP module for Nginx to parse regular expressions

Zlib: The user performs GZIP compression

Openssl: used for nginx HTTPS transmission

yum install -y gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel
Copy the code

Compile the installation

– prefix=/usr/local/soft/nginx means to install nginx into /usr/local/soft/nginx

So there will be a source directory nginx-1.18.0, and a compiled and installed directory nginx

/usr/local/soft/nginx-1.18.0./configure --prefix=/usr/local/soft/nginx make && sudo make install CD /usr/local/soft/nginx/Copy the code

Test whether the configuration is successful:

/usr/local/soft/nginx/sbin/nginx -t -c /usr/local/soft/nginx/conf/nginx.conf
Copy the code

Start the Nginx

/usr/local/soft/nginx/sbin/nginx
Copy the code

copy vimfile

In order for VIM to view nginx configuration files with syntax highlighting, you need to copy the corresponding files to the VIM directory. First determine where the vimFiles directory is on the local computer.

Find / -name vimfiles CD /usr/local/soft/nginx-1.18.0 cp -r contrib/vim/* /usr/share/vim/vimfiles/Copy the code

Common commands

Nginx reopen # restart nginx reload # reload nginx configuration file, Nginx -s quit # Nginx -s quit # Nginx -s quit # Nginx -s quit # And then exit nginx -? Nginx -t # check if there is a syntax error in the configuration file and if there is a syntax error in the configuration file, Dump and exit nginx -q # mask non-error information during configuration file detection nginx -p prefix # set the prefix path (default :/usr/share/nginx/) nginx -c filename # set the configuration file (default: /etc/nginx-nginx.conf). Nginx-g directives # set the global directives outside the configuration file. Killall nginx # killall nginx processesCopy the code

Nginx implements the reverse proxy

Added access directories and HTML files

/usr/local/soft/nginx
mkdir data/user
cd data/user
touch index.html
vim index.html
Copy the code

Index.html content

Copy the Nginx configuration file to the conf directory and rename nginx.domain.conf

cd /usr/local/soft/nginx/conf
cp -i nginx.conf nginx.domains.conf

Copy the code

Modify the configuration file nginx.domain. conf

vim nginx.domains.conf
Copy the code

The new configuration

DNS mapping of the local server

C:\Windows\System32\drivers\etc

Modifying the hosts File

Add a row: 192.168.1.105 www.beijing.com

Configure the alias to restart Nginx

vim ~/.bashrc alias nstop='cd /usr/local/soft/nginx/sbin/; ./nginx -s stop' alias nstart='./nginx -c /usr/local/soft/nginx/conf/nginx-domains.conf' alias nr='cd /usr/local/soft/nginx/sbin/; ./nginx -s reload' source ~/.bashrc nstop nstartCopy the code

Access to the test

Browser visit www.beijing.com/