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
cat /etc/redhat-release uname -rResult:
CentOS release 6.10 (Final) 2.6.32-754.el6.x86_64Install pcre using yum method:
yum -y install pcre pcre-devel rpm -qa pcre pcre-develResult:
pcre-devel-7.8-7.el6.x86_643.2 Install NginxCheck whether openssl and openssl-devel are installed:pcre-7.8-7.el6.x86_64
rpm -qa openssl openssl-develResult: If not, use yum to install
openssl-1.0.1e-57.el6.x86_64 openssl-devel-1.0.1e-57.el6.x86_64Create the nginx package storage directory:
mkdir -p /app/nginx-1.8.1 mkdir -p /server/tools cd /server/tools/Download nginx software Package: Official address: www.nginx.rog
wget -q http://nginx.org/download/nginx-1.8.1.tar.gzCreate nginx user:
useradd nginx -s /sbin/nologin -MUnzip the software package and enter the unzipped directory:
tar xf nginx-1.8.1.tar.gz cd nginx-1.8.1Compile:
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_moduleInstallation:
make make installCreate a soft link: convenient for use and version upgrade
ln -s /app/nginx-1.8.1/ /app/nginxPre-start test:
/app/nginx/sbin/nginx -tResult:
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 successfulStart the Nginx service and check the port:
/app/nginx/sbin/nginx netstat -utpln | grep 80Result:
tcp 0 0 0 0.0.0.0:80 0.0.0.0:* curl 192.168.1.31Result:
<!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 id="Welcome-nbsp-to-nbsp-nginx">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>4. Nginx directory structure and configuration file
4.2 Nginx main configuration fileGo to comment and display the configuration file:4.1 Nginx directory structure description
tree /app/nginx/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
egrep -v "#|^$" /app/nginx/conf/nginx.conf.default
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区块结束
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!

NGINXUnit can be used to deploy and manage applications in multiple languages. 1) Install NGINXUnit. 2) Configure it to run different types of applications such as Python and PHP. 3) Use its dynamic configuration function for application management. Through these steps, you can efficiently deploy and manage applications and improve project efficiency.

NGINX is more suitable for handling high concurrent connections, while Apache is more suitable for scenarios where complex configurations and module extensions are required. 1.NGINX is known for its high performance and low resource consumption, and is suitable for high concurrency. 2.Apache is known for its stability and rich module extensions, which are suitable for complex configuration needs.

NGINXUnit improves application flexibility and performance with its dynamic configuration and high-performance architecture. 1. Dynamic configuration allows the application configuration to be adjusted without restarting the server. 2. High performance is reflected in event-driven and non-blocking architectures and multi-process models, and can efficiently handle concurrent connections and utilize multi-core CPUs.

NGINX and Apache are both powerful web servers, each with unique advantages and disadvantages in terms of performance, scalability and efficiency. 1) NGINX performs well when handling static content and reverse proxying, suitable for high concurrency scenarios. 2) Apache performs better when processing dynamic content and is suitable for projects that require rich module support. The selection of a server should be decided based on project requirements and scenarios.

NGINX is suitable for handling high concurrent requests, while Apache is suitable for scenarios where complex configurations and functional extensions are required. 1.NGINX adopts an event-driven, non-blocking architecture, and is suitable for high concurrency environments. 2. Apache adopts process or thread model to provide a rich module ecosystem that is suitable for complex configuration needs.

NGINX can be used to improve website performance, security, and scalability. 1) As a reverse proxy and load balancer, NGINX can optimize back-end services and share traffic. 2) Through event-driven and asynchronous architecture, NGINX efficiently handles high concurrent connections. 3) Configuration files allow flexible definition of rules, such as static file service and load balancing. 4) Optimization suggestions include enabling Gzip compression, using cache and tuning the worker process.

NGINXUnit supports multiple programming languages and is implemented through modular design. 1. Loading language module: Load the corresponding module according to the configuration file. 2. Application startup: Execute application code when the calling language runs. 3. Request processing: forward the request to the application instance. 4. Response return: Return the processed response to the client.

NGINX and Apache have their own advantages and disadvantages and are suitable for different scenarios. 1.NGINX is suitable for high concurrency and low resource consumption scenarios. 2. Apache is suitable for scenarios where complex configurations and rich modules are required. By comparing their core features, performance differences, and best practices, you can help you choose the server software that best suits your needs.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment