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











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,

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

In PHP, exception handling is achieved through the try, catch, finally, and throw keywords. 1) The try block surrounds the code that may throw exceptions; 2) The catch block handles exceptions; 3) Finally block ensures that the code is always executed; 4) throw is used to manually throw exceptions. These mechanisms help improve the robustness and maintainability of your code.

There are four main error types in PHP: 1.Notice: the slightest, will not interrupt the program, such as accessing undefined variables; 2. Warning: serious than Notice, will not terminate the program, such as containing no files; 3. FatalError: the most serious, will terminate the program, such as calling no function; 4. ParseError: syntax error, will prevent the program from being executed, such as forgetting to add the end tag.

In PHP, the difference between include, require, include_once, require_once is: 1) include generates a warning and continues to execute, 2) require generates a fatal error and stops execution, 3) include_once and require_once prevent repeated inclusions. The choice of these functions depends on the importance of the file and whether it is necessary to prevent duplicate inclusion. Rational use can improve the readability and maintainability of the code.

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

HTTP request methods include GET, POST, PUT and DELETE, which are used to obtain, submit, update and delete resources respectively. 1. The GET method is used to obtain resources and is suitable for read operations. 2. The POST method is used to submit data and is often used to create new resources. 3. The PUT method is used to update resources and is suitable for complete updates. 4. The DELETE method is used to delete resources and is suitable for deletion operations.
