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.
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
As Web service software
Reverse proxy and load balancing service
Front-end business data caching service
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
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 -r
CentOS release 6.10 (Final) 2.6.32-754.el6.x86_64
yum -y install pcre pcre-devel rpm -qa pcre pcre-devel
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-devel
openssl-1.0.1e-57.el6.x86_64 openssl-devel-1.0.1e-57.el6.x86_64
mkdir -p /app/nginx-1.8.1 mkdir -p /server/tools cd /server/tools/
wget -q http://nginx.org/download/nginx-1.8.1.tar.gz
useradd nginx -s /sbin/nologin -M
tar xf nginx-1.8.1.tar.gz cd nginx-1.8.1
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
make make install
ln -s /app/nginx-1.8.1/ /app/nginx
/app/nginx/sbin/nginx -t
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 80
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>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.2 Nginx main configuration fileGo to comment and display the configuration file:4.1 Nginx directory structure description
tree /app/nginxCopy 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 filesCopy after login
egrep -v "#|^$" /app/nginx/conf/nginx.conf.default
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区块结束
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!