egrep -v "#|^$" /app/nginx/conf/nginx.conf.default
How to deploy Nginx service
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 -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
Copy after login
Result: 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区块结束
Copy after loginNote: There can be multiple server blocks and location blocks.
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!

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

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



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.

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.

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 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.

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? 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.

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.

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.
