Detailed description of nginx basic configuration
1. Advantages and disadvantages of Apache server and nginx: We have used Apache extensively as HTTPServer before. Apache has excellent performance and can provide a variety of rich functions through modules. 1) First of all, Apache's response to the client supports concurrency. After running the httpd daemon process, it will generate multiple child processes/threads at the same time, and each child process/thread responds to the client's request respectively; 2) In addition, Apache can provide static and dynamic services. For example, the parsing of PHP is not implemented through CGI with poor performance but through a module that supports PHP (usually mod_php5, or apxs2). 3) Disadvantages: Therefore, this type of Server, usually called Apache, is a process-based server, which is a multi-process HTTP Server, because it needs to create a child process/thread to respond to each user request; The disadvantage of this is that if there are many concurrent requests (which is very common in large portals), a lot of threads will be needed, which will occupy a lot of system resources, CPU and memory. Therefore, concurrent processing is not Apache's strength. 4)Solution: Currently, there is another WebServer that performs better in terms of concurrency, called asynchronous servers. The most famous ones are Nginx and Lighttpd. So-called asynchronous servers are event-driven in the event-driven programming model, except that concurrent requests from users usually only require a single or several threads. Therefore, it takes up very little system resources. These types are also called lightweight web servers. For example, for 10,000 concurrent connection requests, nginx may only use a few MB of memory; while Apache may need to use hundreds of MB of memory resources. 2. Single use in practice: 1) We don’t need to introduce more about using Apache as HTTP Server alone, it is a very common application; We introduced above that Apache's support for server-side scripts such as PHP is implemented through its own modules, and its performance is superior. 2) We can also use nginx or lighttpd alone as HTTPServer. Similar to Apache, nginx and lighttpd can enrich the server's functions through various modules. They also configure various options through conf configuration files. For PHP, etc., neither nginx nor lighttpd has built-in modules to support PHP, but support it through FastCGI. Lighttpd can provide CGI, FastCGI and SCGI services through modules. Lighttpd is capable of automatically spawning FastCGI backends as well as using externally spawned processes. nginx does not provide the function of processing PHP itself, and needs to provide FastCGI integration of PHP through third-party modules. ------------------------------- rewrites all non-http://bbs.it-home.org/ visits=> ; http://bbs.it-home.org/ server_name web90.***.com; if ($host = "web90.***.com") { rewrite ^(.*)$ http://bbs.it-home.org/$1 permanent; } ----------------------------------nginx stop/smooth restart#p#Paging title#e# nginx signal control TERM,INT close quickly QUIT Close calmly HUP Smooth restart, reload configuration file USR1 reopens the log file, which is more useful when cutting logs USR2 Smoothly upgrade executable program WINCH gracefully closes the work process 1) Stop calmly: kill -QUIT Nginx main process ID kill -QUIT '/usr/local/webserver/nginx/logs/nginx.pid' 2) Quick stop: kill -TERM Nginx main process ID kill -TERM '/usr/local/webserver/nginx/logs/nginx.pid' kill -INTN ginx main process number kill -INT '/usr/local/webserver/nginx/logs/nginx.pid' 3) Force stop all nginx processes pkill -9 nginx 1) Smooth restart kill -HUP nginx main process ID kill -HUP '/usr/local/webserver/nginx/logs/nginx.pid' --------------------------nginx.conf #p#Paging title#e# worker_processes 8; Specify the number of job spawn processes Generally equal to the total number of cores of the CPU or twice the total number of cores. For example, for two quad-core CPUs, the total number of cores is 8
===================== Cut nginx log script regularly every day
Under normal circumstances, the size of compressed html, css, js, php, jhtml and other files can be reduced to 25% of the original size. In other words, the original 100k html will only have 25k left after compression. This will undoubtedly save a lot of bandwidth and also reduce the load on the server. Configuring gzip in nginx is relatively simple Under normal circumstances, just add the following lines of configuration to the http section of nginx.conf Quote gzip on; gzip_min_length 1000; gzip_buffers 4 8k; gzip_types text/plain application/x-javascript text/css text/html application/xml; Restart nginx You can use the web page gzip detection tool to detect whether gzip is enabled on the web page http://gzip.zzbaike.com/ ---------------How to redirect nginx error page error_page 404 /404.html; This 404.html is guaranteed to be in the html directory under the nginx home directory. If you need to jump directly to another address after a 404 error occurs, you can directly set it as follows: error_page 404 http://bbs.it-home.org/ ; Common 403, 500 and other errors can be defined in the same way. #p#Paging title#e# Special attention should be paid to the fact that the page size of the 404.html file must exceed 512k, otherwise it will be replaced by the IE browser's default error page. ----------------------------------Virtual host configuration
|

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



Alipay PHP...

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.
