Home Web Front-end HTML Tutorial Detailed steps for installing nginx under linux/centos (rpm installation and source code installation)_html/css_WEB-ITnose

Detailed steps for installing nginx under linux/centos (rpm installation and source code installation)_html/css_WEB-ITnose

Jun 24, 2016 am 11:59 AM
nginx Install step Source code detailed

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_params

fastcgi_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)

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1662
14
PHP Tutorial
1261
29
C# Tutorial
1234
24
How to configure nginx in Windows How to configure nginx in Windows Apr 14, 2025 pm 12:57 PM

How to configure Nginx in Windows? Install Nginx and create a virtual host configuration. Modify the main configuration file and include the virtual host configuration. Start or reload Nginx. Test the configuration and view the website. Selectively enable SSL and configure SSL certificates. Selectively set the firewall to allow port 80 and 443 traffic.

How to start containers by docker How to start containers by docker Apr 15, 2025 pm 12:27 PM

Docker container startup steps: Pull the container image: Run "docker pull [mirror name]". Create a container: Use "docker create [options] [mirror name] [commands and parameters]". Start the container: Execute "docker start [Container name or ID]". Check container status: Verify that the container is running with "docker ps".

How to check the name of the docker container How to check the name of the docker container Apr 15, 2025 pm 12:21 PM

You can query the Docker container name by following the steps: List all containers (docker ps). Filter the container list (using the grep command). Gets the container name (located in the "NAMES" column).

How to check whether nginx is started How to check whether nginx is started Apr 14, 2025 pm 01:03 PM

How to confirm whether Nginx is started: 1. Use the command line: systemctl status nginx (Linux/Unix), netstat -ano | findstr 80 (Windows); 2. Check whether port 80 is open; 3. Check the Nginx startup message in the system log; 4. Use third-party tools, such as Nagios, Zabbix, and Icinga.

How to create containers for docker How to create containers for docker Apr 15, 2025 pm 12:18 PM

Create a container in Docker: 1. Pull the image: docker pull [mirror name] 2. Create a container: docker run [Options] [mirror name] [Command] 3. Start the container: docker start [Container name]

How to check nginx version How to check nginx version Apr 14, 2025 am 11:57 AM

The methods that can query the Nginx version are: use the nginx -v command; view the version directive in the nginx.conf file; open the Nginx error page and view the page title.

How to configure cloud server domain name in nginx How to configure cloud server domain name in nginx Apr 14, 2025 pm 12:18 PM

How to configure an Nginx domain name on a cloud server: Create an A record pointing to the public IP address of the cloud server. Add virtual host blocks in the Nginx configuration file, specifying the listening port, domain name, and website root directory. Restart Nginx to apply the changes. Access the domain name test configuration. Other notes: Install the SSL certificate to enable HTTPS, ensure that the firewall allows port 80 traffic, and wait for DNS resolution to take effect.

What to do if nginx server is hung What to do if nginx server is hung Apr 14, 2025 am 11:42 AM

When the Nginx server goes down, you can perform the following troubleshooting steps: Check that the nginx process is running. View the error log for error messages. Check the syntax of nginx configuration. Make sure nginx has the permissions you need to access the file. Check file descriptor to open limits. Confirm that nginx is listening on the correct port. Add firewall rules to allow nginx traffic. Check reverse proxy settings, including backend server availability. For further assistance, please contact technical support.

See all articles