Install nginx rpm package under Centos www.169it.com
1 Download an rpm package from the nginx official website, the download address is: http:// nginx.org/en/download.html
wget http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch. rpm
2 Install this rpm package
rpm -ivh nginx-release-centos-6-0.el6.ngx.noarch.rpm
An error will occur during the installation process Tip:
warning: nginx-release-centos-6-0.el6.ngx.noarch.rpm: Header V4 RSA/SHA1 Signature, key ID 7bd9bf62: NOKEY
Just ignore it
3 Start the formal installation of nginx
yum install nginx
A lot of information will be displayed: Is this ok [y/N]:
Enter y, After the screen scrolls for a while, the installation is completed, and the final prompt "Complete!" means the installation is complete.
4 Several default directories of nginx
Enter the command: whereis nginx
nginx: /usr/sbin/nginx /etc/nginx /usr/share/nginx
1) Configuration directory: /etc/nginx/
2) PID directory: /var/run/nginx.pid
3) Error log: /var/log/ nginx/error.log
4) Access log: /var/log/nginx/access.log
5) Default site directory: /usr/share/nginx/html
5 Common commands
1) Start nginx: nginx
2) Restart nginx: killall -HUP nginx
3) Test nginx configuration: nginx -t
6 Nginx cannot be accessed off-site?
A common problem after just installing nginx is that it cannot be accessed outside the site, but wget and telnet on the local machine are normal. Outside of the server, neither other hosts on the LAN nor hosts on the Internet can access the site. If
is using telnet, it will prompt:
Connecting to 192.168.0.xxx...Cannot open the connection to the host. At port 80: Connection failed
If If you use the wget command, the prompt is:
Connecting to 192.168.0.100:80... failed: No route to host.
If the above fault occurs, it is likely to be caused by the CentOS firewall. After blocking port 80, try executing the following command to open port 80:
iptables -I INPUT -p tcp --dport 80 -j ACCEPT
Then use:
/etc/init.d/iptables status
Check the current firewall rules, if you find such one:
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt: 80
means that the firewall rules have been added successfully, and access outside the site will be normal.
Generally refer to the source code installation steps for nginx under Linux
Generally we need to install pcre and zlib first, the former In order to rewrite rewrite, the latter is for gzip compression.
1. Select the source code directory
can be any directory. The one selected in this article is /usr/local/src
cd /usr/local/src
2. Install the PCRE library
ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/ Download the latest PCRE source code package, use the following commands to download, compile and install PCRE package:
cd /usr/local/src
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.21.tar .gz
tar -zxvf pcre-8.21.tar.gz
cd pcre-8.21
./configure
make
make install
3. Install zlib library
http://zlib.net/zlib-1.2.8.tar.gz Download the latest zlib source package, use the following command to download, compile and install zlib package:
cd /usr/local/src
wget http://zlib.net/zlib-1.2.8.tar.gz
tar -zxvf zlib -1.2.8.tar.gz
cd zlib-1.2.8
./configure
make
make install
4. Install ssl (some vps do not have ssl installed by default)
cd /usr/local/src
wget http://www.openssl.org/source/openssl-1.0.1c .tar.gz
tar -zxvf openssl-1.0.1c.tar.gz
5. Install nginx
Nginx generally has two versions, namely stable version and Development version, you can choose one of these two versions according to your purpose. The following are the detailed steps to install Nginx to the /usr/local/nginx directory:
cd /usr/local/src
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 --sbin-path=/usr/local/nginx/nginx
--conf-path=/usr/ local/nginx/nginx.conf
--pid-path=/usr/local/nginx/nginx.pid
--with-http_ssl_module
--with- pcre=/usr/local/src/pcre-8.21
--with-zlib=/usr/local/src/zlib-1.2.8
--with-openssl=/usr /local/src/openssl-1.0.1c
make
make install
--with-pcre=/usr/src/pcre- 8.21 refers to the source code path of pcre-8.21.
--with-zlib=/usr/src/zlib-1.2.7 refers to the source code path of zlib-1.2.7.
After successful installation, the /usr/local/nginx directory is as follows:
fastcgi.conf >
fastcgi.conf.default logs scgi_paramsfastcgi_params mime.types scgi_params.default ault uwsgi_params
html uwsgi_params.default
koi-utf nginx.conf nginx.conf win-utf
6. Start
Make sure that port 80 of the system is not occupied by other programs, run /usr/local/nginx/nginx Command to start Nginx,
netstat -ano|grep 80
If no result is found, execute it. If there is a result, ignore this step (it must be started with sudo under ubuntu, otherwise it can only be started in the foreground Run)
sudo /usr/local/nginx/nginx
Open the browser to access the IP of this machine. If the browser displays Welcome to nginx!, it means that Nginx has been installed and run successfully.
Source of this article: Detailed steps for installing nginx under linux/centos (rpm installation and source code installation)