A list,
-
Install Nginx according to the main CentOS infrastructure (Nginx, Git, Lrzsz).
-
yum
Basic use of -
Accessing the Public IP address from the browser before installation (http://xxx.xxx.xx.xxx/)
Installation, startup, configuration file directory
-
Yum install nginx
$ yum install -y nginx Copy the code
After installation, revisit the previous IP. (By default, Nginx is automatically started after installation, so you can access it directly. If not, you can manually start Nginx.)
-
Nginx configuration file directory: Nginx configuration file usage (nginx.conf)
/etc/nginx/nginx.conf Copy the code
-
Nginx startup command directory
/usr/sbin/nginx Copy the code
-
Nginx projects are stored in the root directory (recommended), which is the folder in which projects are placed
/home Copy the code
-
Nginx startup: Nginx common commands (not recommended)
$nginx or $/usr/sbin/nginxCopy the code
-
Systemctl Startup mode (recommended)
CentOS 7.x starts to use systemd services instead of daemons. The commands used to manage system startup and services are replaced by systemctl commands.
Advantages: such as power failure, crash or other factors caused by the process hanging, will automatically help you to start up, when the number of background mounted process, you do not need to manually start again, the original above need to manually start, of course, there are other benefits.
Systemctl start nginx systemctl stop nginx systemctl restart nginx systemctl status nginxCopy the code
-
Check whether Nginx has been started in the startup process list
$ps - aux | grep nginx or: $ps - ef | grep nginxCopy the code
-
To kill a process, PID is found in the process list, usually as the second field of each process.
$kill PID // Forcibly kill the process $kill -9 PIDCopy the code
3. Create a configuration file and configure a VM separately
-
Configuration file Directory
/etc/nginx/nginx.conf Copy the code
-
If you open the configuration file, you will see include /etc/nginx/conf.d/*.conf; In this line, go to this folder and create a configuration file ending with.conf. It is recommended that each configuration file corresponds to a server.
-
Go to the configuration folder, create a test configuration file, and add a VM.
$ cd /etc/nginx/conf.d/ Copy the code
Create a new test.conf file
$ touch test.conf Copy the code
Editing a Configuration File
$ vim test.conf Copy the code
Configure a server where the root directory points to the /home/test directory and the target file is index.html
Server {# listen port 8082; # server_name www.dzm.com; # root /home/test; Location / {index index.html; } # location/API / {# proxy_pass http://platform-api.yxfengsheng.com/; #}}Copy the code
Save and exit: Press ESC to exit the editing mode and enter :wq to save and exit.
-
Go to the /home root directory, create the test project folder, and add the contents of the index.html project file
$ cd /home Copy the code
Create the Test project folder
$ mkdir test Copy the code
Go to the Test project folder
$ cd test/ Copy the code
Create the index.html project file
$ touch index.html Copy the code
Add web content
$ vim index.html Copy the code
<! DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, <title>Document</title> </head> <body> DZM CentOS Test </body> </ HTML >Copy the code
Save and exit: Press ESC to exit the editing mode and enter :wq to save and exit.
-
Restart or update the nginx configuration.
$ systemctl restart nginx Copy the code
-
Access public IP address :8082. Port 8082 has just been configured.