The installation method of Nginx in CentOS
- 2020-05-13 04:42:42
- OfStack
My machine is CentOS, so this article is based on the installation of CentOS, Nginx has two installation methods under CentOS, yum installation and source installation.
1. yum installation
The yum installation is very simple. First, we need to add the warehouse source for the EPEL package. Use the following command
yum -y install epel-release
Then execute the install Nginx command.
yum -y install nginx
2. Source installation
Source installation requires downloading the source code and the corresponding dependencies from the official website, and then compiling the installation.
The packages that Nginx relies on are:
openssl-devel
zlib-devel
pcre-devel
gcc
In general, we only need to install zlib-devel and pcre-devel. Many centos of gcc have already been installed.
1. Install the PCRE library
# Take the latest PCRE Source package, download compile and install using the following command PCRE Package:
ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/
cd /opt/soft
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.40.tar.gz ・
tar -zxvf pcre-8.40.tar.gz
cd pcre-8.40
./configure
make
make install
2. Install the zlib library
cd /opt/soft
wget http://zlib.net/zlib-1.2.10.tar.gz
tar -zxvf zlib-1.2.10.tar.gz
cd zlib-1.2.10
./configure
make
make install
3. Install Nginx
cd /opt/soft
wget http://nginx.org/download/nginx-1.4.2.tar.gz
tar -zxvf nginx-1.4.2.tar.gz
cd nginx-1.4.2
./configure
make
make install
If you directly execute./configure, then nginx is installed to the default path (the default path is installed to run /usr/local/nginx). The custom installation steps are as follows: install to the /soft/nginx directory
./configure
--sbin-path=/opt/soft/nginx/sbin
--conf-path=/soft/nginx/nginx.conf
--pid-path=/soft/nginx/nginx.pid
--with-http_ssl_module
--with-pcre=/opt/soft/pcre-8.40
--with-zlib=/opt/soft/zlib-1.2.10
Note the version number installed, directory 1, and the package-dependent path.
3. Start, restart and close Nginx
1. Firewall setup
Through the above command operation, Nginx has been installed. First, we need to open the firewall and port 80 opened by Nginx.
/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT
/etc/rc.d/init.d/iptables save
/etc/init.d/iptables restart
2. Start
Start Nginx and run Nginx directly
/usr/local/nginx/sbin/nginx
3. Restart
/usr/local/nginx/sbin/nginx -s restart
4. Close the
/usr/local/nginx/sbin/nginx -s stop
5. Test
Later, we will configure the configuration file of Nginx. After modifying the configuration file, we can test the image of the configuration file to determine whether the modified configuration is correct
/usr/local/nginx/sbin/nginx -t
After the above steps, launch Nginx and access port 80 of the server to see the Nginx welcome page