1. Install dependencies
#GCC installation, nginx source code compilation required
yum install gcc-c++
#PCRE pcre-devel installed, nginx's HTTP module uses PCRE to parse regular expressions
yum install -y pcre pcre-devel
#Zlib installation, nginx uses Zlib to gzip the contents of HTTP packages yum install -y zlib zlib-devel #Nginx supports not only HTTP but also HTTPS (that is, HTTP over SSL). yum install -y openssl openssl-devel Copy the code
2. Use the wget command to download (recommended)
#Version you can choose the stable version
Wget -c https://nginx.org/download/nginx-1.16.1.tar.gzCopy the code
3. The installation
#Decompress to the specified directory
Tar -zxvf nginx-1.16.1.tar.gz -c /opt/bin
#Enter the directory
CD/opt/bin/nginx - 1.16.1 #Use default Settings ./configure #Compile the installation make make install #Find the installation path, the default is this path [root @ VM_0_3_centos nginx - 1.16.1] # whereis nginxnginx: /usr/local/nginx #Start and stop nginx cd /usr/local/nginx/sbin/ #. / nginx start/nginx -s stop # Stop the nginx process by executing the kill command/nginx -s quit # Stop the nginx process until it completes its task/nginx -s reload # Reload the configuration file. Run this command to modify nginx.conf #Restart nginx. You are advised to stop nginx before restarting it ./nginx -s stop ./nginx #View the nginx process [root@VM_0_12_centos ~]# ps aux|grep nginx Root 21888 0.0 0.0 20556 616? Ss 21:24 0:00 nginx: master process ./nginxNobody 21889 0.0 0.0 23092 1636? S 21:24 0:00 nginx: worker processRoot 25687 0.0 0.0 112712 960 PTS /0 R+ 21:52 0:00 grep --color=auto nginxCopy the code
4. Set automatic startup
#The first step
vi /etc/rc.local
#Add a line
/usr/local/nginx/sbin/nginx
#Setting Execution Permission cd /etc chmod 755 rc.local Copy the code
Enter the server IP address to access the Nginx page.
5. Configure the domain name mapping
Nginx configuration files are stored in the /usr/local/nginx/conf/ directory. The file name is nginx.conf.
#Go to the nginx configuration file directory
cd /usr/local/nginx/conf
#Modifying a Configuration File
vi nginx.conf
Copy the code
Domain name Configuration:
Just change the contents of server_name and Location.
listen 80;
#The domain name
server_name www.example.com;
#Access address Settings
location / {
proxy_pass http://localhost:9000; } Copy the code
After the modification, reload the configuration file:
cd /usr/local/nginx/sbin/
./nginx -s reload
Copy the code
This article is formatted using MDNICE