Table of Contents
1. Introduction to Nginx:
1.1 What is Nginx?
1.2 Nginx main features
1.3 Main functional applications of Nginx software
2. Nginx Web service
2.1 Nginx as a web server application scenario
2.2 How to choose a Web server
egrep -v "#|^$" /app/nginx/conf/nginx.conf.default
Copy after login
" >
egrep -v "#|^$" /app/nginx/conf/nginx.conf.default
Copy after login
Home Operation and Maintenance Nginx How to deploy Nginx service

How to deploy Nginx service

May 12, 2023 am 10:13 AM
nginx

1. Introduction to Nginx:

1.1 What is Nginx?

Nginx ("engine x") is an open source that supports high-performance, high-concurrency www service and proxy service software.

was developed by Russian Igor Sysoev and was originally used on the large Russian website www.rambler.ru.

Nginx has the characteristics of high concurrency and low system resource usage.

Nginx can run on UNIX, Linux, DSB, Mac OS X, Solaris and Windows operating systems.

1.2 Nginx main features

Supports high concurrency: can support tens of thousands of concurrent connections

Low resource consumption: under 30,000 concurrent connections, the first 10 threads consume less than 10% of memory 200MB.

Can do HTTP reverse proxy and accelerated caching, that is, load balancing function, built-in health check function for RS node server

Have caching function of professional caching software such as Squid

Support asynchronous network I/O event model

1.3 Main functional applications of Nginx software

As Web service software

Reverse proxy and load balancing service

Front-end business data caching service

2. Nginx Web service

2.1 Nginx as a web server application scenario

Use Nginx to run HTML, JS, CSS, small pictures and other static data

Nginx combines with FastCGI to run PHP and other dynamic programs

Nginx combines Tomcat/Resin, etc. to support Java dynamic programs

2.2 How to choose a Web server

At work, according to Need to choose the appropriate business service software:

  • Static business: High concurrency scenarios, Nginx is preferred

  • Dynamic business: Both Nginx and Apache Yes, it is recommended that Nginx

  • static dynamic business: recommended Nginx

##3 Compile and install Nginx

There are many installation methods, this article Use the compile and install method. If large-scale deployment is required, the rpm package can be customized according to business requirements and then installed through Ansible.

3.1 Install pcre library

Check the current system version:

cat /etc/redhat-release
uname -r
Copy after login

Result:

CentOS release 6.10 (Final)
2.6.32-754.el6.x86_64
Copy after login

Install pcre using yum method:

yum -y install pcre pcre-devel
rpm -qa pcre pcre-devel
Copy after login

Result:

pcre-devel-7.8-7.el6.x86_64

pcre-7.8-7.el6.x86_64

3.2 Install Nginx

Check whether openssl and openssl-devel are installed:

rpm -qa openssl openssl-devel
Copy after login

Result: If not, use yum to install

openssl-1.0.1e-57.el6.x86_64
openssl-devel-1.0.1e-57.el6.x86_64
Copy after login

Create the nginx package storage directory:

mkdir -p /app/nginx-1.8.1
mkdir -p /server/tools
cd /server/tools/
Copy after login

Download nginx software Package:

Official address: www.nginx.rog

wget -q http://nginx.org/download/nginx-1.8.1.tar.gz
Copy after login

Create nginx user:

useradd nginx -s /sbin/nologin -M
Copy after login

Unzip the software package and enter the unzipped directory:

tar xf nginx-1.8.1.tar.gz
cd nginx-1.8.1
Copy after login

Compile:

The compiled module can be viewed through ./configure --help

./configure --user=nginx --group=nginx --prefix=/app/nginx-1.8.1/ --with-http_stub_status_module --with-http_ssl_module
Copy after login

Installation:

make
make install
Copy after login

Create a soft link: convenient for use and version upgrade

ln -s /app/nginx-1.8.1/ /app/nginx
Copy after login

Pre-start test:

/app/nginx/sbin/nginx -t
Copy after login

Result:

nginx: the configuration file /app/nginx-1.8.1//conf/nginx.conf syntax is oknginx: configuration file /app /nginx-1.8.1//conf/nginx.conf test is successful

Start the Nginx service and check the port:

/app/nginx/sbin/nginx
netstat -utpln | grep 80
Copy after login

Result:

tcp 0 0 0 0.0.0.0:80 0.0.0.0:* curl 192.168.1.31

Result:

<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h2>Welcome to nginx!</h2>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/" rel="external nofollow" >nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/" rel="external nofollow" >nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>
Copy after login

4. Nginx directory structure and configuration file

4.1 Nginx directory structure description

tree /app/nginx
Copy after login
/app/nginx
├── client_body_temp
├── conf							#nginx配置文件目录
│   ├── fastcgi.conf				#fastcgi相关参数配置文件
│   ├── fastcgi.conf.default
│   ├── fastcgi_params				#fastcgi参数文件
│   ├── fastcgi_params.default
│   ├── koi-utf
│   ├── koi-win
│   ├── mime.types					#媒体类型
│   ├── mime.types.default
│   ├── nginx.conf					#Nginx主配置文件
│   ├── nginx.conf.default
│   ├── scgi_params					#scgi配置文件
│   ├── scgi_params.default
│   ├── uwsgi_params				#uwsgi配置文件
│   ├── uwsgi_params.default
│   └── win-utf
├── fastcgi_temp					#fastcgi临时数据文件
├── html							#默认站点目录
│   ├── 50x.html					#错误页面显示文件
│   └── index.html					#默认的站点首页文件
├── logs							#默认日志路径
│   ├── access.log					#默认访问日志文件
│   ├── error.log					#默认错误日志文件
│   └── nginx.pid					#Nginx的pid文件
├── proxy_temp						#临时目录
├── sbin							#Nginx命令目录
│   ├── nginx						#启动命令
│   └── nginx.old
├── scgi_temp						#临时目录
└── uwsgi_temp						#临时目录

9 directories, 22 files
Copy after login
4.2 Nginx main configuration file

Go to comment and display the configuration file:

egrep -v "#|^$" /app/nginx/conf/nginx.conf.default
Copy after login

Result:

worker_processes  1;                            #worker进程数量
events {                                        #事件区块开始
    worker_connections  1024;                    #单worker进程支持的最大连接
}                                                #事件区块结束
http {                                            #HTTP区块开始
    include       mime.types;                    #支持的媒体类型库
    default_type  application/octet-stream;        #默认媒体类型
    sendfile        on;                            #开启高效传输模式
    keepalive_timeout  65;                        #连接超时
    server {                                    #server区块开始
        listen       80;                        #服务端口,默认80
        server_name  localhost;                    #域名主机名
        location / {                            #location区块开始
            root   html;                        #站点根目录
            index  index.html index.htm;        #默认首页文件
        }                                        #location区块结束
        error_page   500 502 503 504  /50x.html;#对应状态码及回应
        location = /50x.html {                    #location开始回应50x.html
            root   html;                        #站点目录为html
        }                                        
    }
}                                                #HTTP区块结束
Copy after login
Note: There can be multiple server blocks and location blocks.

The above is the detailed content of How to deploy Nginx service. For more information, please follow other related articles on the PHP Chinese website!

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)

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.

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 start nginx server How to start nginx server Apr 14, 2025 pm 12:27 PM

Starting an Nginx server requires different steps according to different operating systems: Linux/Unix system: Install the Nginx package (for example, using apt-get or yum). Use systemctl to start an Nginx service (for example, sudo systemctl start nginx). Windows system: Download and install Windows binary files. Start Nginx using the nginx.exe executable (for example, nginx.exe -c conf\nginx.conf). No matter which operating system you use, you can access the server IP

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 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 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 deploy jar program in nginx How to deploy jar program in nginx Apr 14, 2025 pm 12:09 PM

To deploy a JAR program on Nginx, seven steps need to be followed: 1) Install JRE, 2) Install Nginx, 3) Configure Nginx, 4) Deploy JAR, 5) Grant execution permissions, 6) Restart Nginx, 7) Verify deployment.

How to run nginx apache How to run nginx apache Apr 14, 2025 pm 12:33 PM

To get Nginx to run Apache, you need to: 1. Install Nginx and Apache; 2. Configure the Nginx agent; 3. Start Nginx and Apache; 4. Test the configuration to ensure that you can see Apache content after accessing the domain name. In addition, you need to pay attention to other matters such as port number matching, virtual host configuration, and SSL/TLS settings.

See all articles