1. Dependencies required for installation
yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel
2. Download the compressed package
Download link: http://nginx.org/download/
Choose the version you want
# 进入一个目录,理论上来讲,随便一个目录都可以。但网上很多人都用这个目录
cd /usr/local/
# 下载压缩包到当前目录下
wget http://nginx.org/download/nginx-1.9.9.tar.gz
2. Unzip the compressed package
tar -zxvf nginx-1.9.9.tar.gz -C /usr/local/
Note that the contents of the decompressed nginx-1.9.9 folder are required for nginx to compile and install. This directory is equivalent to the directory of the installation program. At this time, nginx has not been installed. Its installation is source code compilation and installation, which is the reason for the previous need to install related dependencies.
Parameter item science:
-z: Since it is a compressed package in ".gz" format, it needs to be decompressed with the gzip tool, so this parameter needs to be specified
-j: Use the bzip2 tool to decompress the compressed package in ".bz2" format
-J: Use the xz tool to decompress the compressed package in ".xz" format
-C target directory: Specify which directory to extract to. Since it is currently under /usr/local, it does not need to be specified, the default current directory
-x: Unzip. Must bring
-v: output decompression details
-f: Use archive files. Must bring
3. Execute the configuration script before compiling
# 此时处于/usr/local,进入nginx-1.9.9目录,方便执行脚本
cd nginx-1.9.9
# 执行配置脚本
./configure --prefix=/usr/local/soft/nginx --with-http_stub_status_module --with-http_ssl_module
Compilation parameter --with-http_ssl_module, so wait a moment to bring the ssl module when compiling, let nginx support the ssl function (https). Otherwise, when the SSL certificate is needed in the future, it will be troublesome to modify.
./configure is green, indicating that it is an executable file
Linux file color science:
Green file -------- executable file, executable program
Red file-----------compressed file or package file
Blue file ---------- directory
White files ---------- ordinary, such as text files, configuration files, source code files, etc.
Light blue file----------link file, mainly the file created with ln command
Flashing red ---------- There is a problem with the linked file
Yellow file ---------- means device file
Gray file----------means other files
4. Compile
make
5. Installation
make install
The installed nginx is under /usr/local. /Nginx-1.9.9 under this directory is the directory of the installation program, and other things are the things of the main nginx program
6, start
Directory: /usr/local/nginx
conf: configuration file
html: web file
logs: log file
sbin: executable script
# 进入该目录,方便执行脚本
cd /usr/local/nginx/sbin
# 启动
./nginx
# 停止
./nginx -s stop
# 重启
./nginx -s reload
If you encounter the above screenshot error when restarting, then:./nginx -c /usr/local/nginx/conf/nginx.conf ./nginx -s reload
If the following error occurs during startup, it is because the port is occupied. Two situations:
1. The default configuration is port 80, which is already occupied (may be occupied by apache)
2. nginx has been started, and you start nginx repeatedly
7. View the nginx process
ps -ef | grep nginx
Note: The service processes started here are actually 4 processes, because when the nginx process is started, it will be accompanied by a daemon to protect the formal process from being abnormally terminated; if the daemon returns to nginx inheritance is terminated, it will Automatically restart the process.
The daemon process is generally called the master process, and the business process is called the worker process
To set nginx to start, just add the startup code to rc.local.
vim /etc/rc.local
Then add /usr/local/nginx/sbin/nginx at the bottom
8. Visit the homepage
I did not modify the nginx configuration file, the default port is 80. When the project is deployed, go to study how to do the configuration file. . . .
If you are accessing nginx on the virtual machine on the host (windows), if 404, it may be because the port corresponding to nginx is protected by the Linux firewall. The firewall can be turned off, but it is recommended to configure the release rules. Baidu by yourself.