Migrating from Nginx to Nginx
- Install Nginx.
- Method 1: Compile source code.
- Download the source package of the required version.
- Decompress the Nginx package.
1tar -zxvf nginx-1.18.0.tar.gz
- Check the source Nginx compilation parameters.
strings Source_Nginx_binary_file_path | grep "configure arguments"
Command output:
1configure arguments: --prefix=/usr/local/nginx --conf-path=/home/nginx_confs/nginx.conf
- Go to the directory generated after the decompression and run the ./configure command. (Set the compilation parameters based on the command output of the previous step.)
1./configure --prefix=/usr/local/nginx --conf-path=/home/nginx_confs/nginx.conf
If the compilation fails due to missing dependencies, download the missing dependencies as prompted.
- Perform the compilation and installation.
1make && make install
- Method 2: Install the RPM package.
- Method 1: Compile source code.
- Migrate configuration files and directories.
- Copy related files and directories in the source Nginx installation path to the target environment.
- Copy the files and directories specified in the source Nginx compilation parameters. Migrate the source configuration files and log files or directories to the target environment based on the path to the source Nginx compilation parameters.
If the content to be migrated is a directory, filter out binary files, executable files, and .so files in the directory and copy other files to the target path.
- Migrate other files and directories introduced in the configuration file.
Check the configuration files and copy other files and directories in the configuration files to the corresponding paths in the target environment.
- If an absolute path is used, copy the related files and directories to the corresponding path in the target environment based on the source path structure. For example:
The root configuration in the source configuration file uses the HTML directory root /usr/data/html.
1cp -r /usr/data/html /usr/data/
- If a relative path is used, copy the related files and directories to the corresponding path in the target environment based on the structure of the source relative path.
- Example directories:
Source Nginx installation path: /usr/local/nginx
The root configuration in the source configuration file uses the HTML directory root html.
Target Nginx installation path: /usr/local/nginx1cp -r /usr/local/nginx/html /usr/local/nginx/
- Example files:
Source configuration file path: /usr/local/nginx/conf
The include configuration in the source configuration file references the mime.types file: include mime.types.
Directory of the target Nginx configuration file: /usr/local/nginx/conf
1cp /usr/local/nginx/conf/mime.types /usr/local/nginx/conf
- Example directories:
- If an absolute path is used, copy the related files and directories to the corresponding path in the target environment based on the source path structure. For example:
- Check the Nginx configuration.
cd Target_Nginx_installation_path/sbin ./nginx -t
If an error is reported, rectify the fault based on the error information.
- Start the Nginx service.
cd Target_Nginx_installation_path/sbin ./nginx