search
HomeBackend DevelopmentPHP TutorialA brief introduction to nginx configuration and parameters

A brief introduction to nginx configuration and parameters

Aug 16, 2017 am 10:02 AM
nginxparameterConfiguration


Summary: nginx basic configuration and parameter description

#Run user
user nobody;
#Start the process , usually set to be equal to the number of cpu
worker_processes 1;

#Global error log and PID file
#error_log logs/error.log;
#error_log logs/error.log notice ;
#error_log logs/error.log info;

#pid logs/nginx.pid;

#Working mode and maximum number of connections
events {
#epoll It is a method of multiplexing IO (I/O Multiplexing).
# It is only used for linux2.6 and above kernels. It can greatly improve the performance of nginx.
use epoll;

# The maximum number of concurrent connections for a single background worker process
worker_connections 1024;

# The total number of concurrent connections is the product of worker_processes and worker_connections
# That is, max_clients = worker_processes * worker_connections
# After setting the reverse In the case of proxy, max_clients = worker_processes * worker_connections / 4 Why
# Why should the reverse proxy above be divided by 4? It should be said to be an empirical value
# According to the above conditions, Nginx Server can handle it under normal circumstances The maximum number of connections is: 4 * 8000 = 32000
# The setting of the worker_connections value is related to the physical memory size
# Because concurrency is subject to IO constraints, the value of max_clients must be less than the maximum number of files that the system can open
# And The maximum number of files that can be opened by the system is proportional to the memory size. Generally, the number of files that can be opened on a machine with 1GB of memory is about 100,000.
# Let’s take a look at the number of file handles that can be opened by a VPS with 360M of memory:
# $ cat /proc/sys/fs/file-max
# Output 34336
# 32000 # Therefore, the value of worker_connections needs to be set appropriately based on the number of worker_processes processes and the maximum total number of files that the system can open
# so that the total number of concurrent concurrencies is less than the maximum number of files that the operating system can open
# The essence is to configure according to the physical CPU and memory of the host.
# Of course, the theoretical total number of concurrency may deviate from the actual number, because the host has other working processes that need to consume system resources.
# ulimit -SHn 65535

}

http {
#Set the mime type, the type is defined by the mime.type file
include mime.types;
default_type application/octet-stream;
#Set log format
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log logs/access.log main;

#The sendfile instruction specifies whether nginx calls the sendfile function (zero copy mode) to output the file.
#For ordinary applications, it must be set to on,
#If it is used for disk IO heavy load applications such as downloading, it can be set to off,
# to balance the disk and network I/O processing speed and reduce the system uptime.
sendfile on;
# tcp_nopush on;

#Connection timeout
#keepalive_timeout 0;
keepalive_timeout 65;
tcp_nodelay on;

#Enable gzip compression
gzip on;
gzip_disable "MSIE [1-6].";

#Set request buffer
client_header_buffer_size 128k;
large_client_header_buffers 4 128k;

#Set virtual host configuration
server {
#Listen to port 80
listen 80;
#Define using www.nginx.cn to access
server_name www.nginx.cn;

#Define the default of the server Website root directory location
root html;

#Set the access log of this virtual host
access_log logs/nginx.access.log main;

#Default request
location / {

#Define the name of the homepage index file
index index.php index.html index.htm;

}

# Define the error prompt page
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}

#Static files, nginx handles them by itself
location ~ ^/(images|javascript| js|css|flash|media|static)/ {

#Expiration is 30 days, static files are not updated very much, the expiration can be set larger,
#If it is updated frequently, it can be set smaller.
expires 30d;
}

#PHP script requests are all forwarded to FastCGI for processing. Use FastCGI default configuration.
location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

#Access to .htxxx files is prohibited
location ~ /.ht {
deny all;
}

}
}


The above is the detailed content of A brief introduction to nginx configuration and parameters. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
PHP Email: Step-by-Step Sending GuidePHP Email: Step-by-Step Sending GuideMay 09, 2025 am 12:14 AM

PHPisusedforsendingemailsduetoitsintegrationwithservermailservicesandexternalSMTPproviders,automatingnotificationsandmarketingcampaigns.1)SetupyourPHPenvironmentwithawebserverandPHP,ensuringthemailfunctionisenabled.2)UseabasicscriptwithPHP'smailfunct

How to Send Email via PHP: Examples & CodeHow to Send Email via PHP: Examples & CodeMay 09, 2025 am 12:13 AM

The best way to send emails is to use the PHPMailer library. 1) Using the mail() function is simple but unreliable, which may cause emails to enter spam or cannot be delivered. 2) PHPMailer provides better control and reliability, and supports HTML mail, attachments and SMTP authentication. 3) Make sure SMTP settings are configured correctly and encryption (such as STARTTLS or SSL/TLS) is used to enhance security. 4) For large amounts of emails, consider using a mail queue system to optimize performance.

Advanced PHP Email: Custom Headers & FeaturesAdvanced PHP Email: Custom Headers & FeaturesMay 09, 2025 am 12:13 AM

CustomheadersandadvancedfeaturesinPHPemailenhancefunctionalityandreliability.1)Customheadersaddmetadatafortrackingandcategorization.2)HTMLemailsallowformattingandinteractivity.3)AttachmentscanbesentusinglibrarieslikePHPMailer.4)SMTPauthenticationimpr

Guide to Sending Emails with PHP & SMTPGuide to Sending Emails with PHP & SMTPMay 09, 2025 am 12:06 AM

Sending mail using PHP and SMTP can be achieved through the PHPMailer library. 1) Install and configure PHPMailer, 2) Set SMTP server details, 3) Define the email content, 4) Send emails and handle errors. Use this method to ensure the reliability and security of emails.

What is the best way to send an email using PHP?What is the best way to send an email using PHP?May 08, 2025 am 12:21 AM

ThebestapproachforsendingemailsinPHPisusingthePHPMailerlibraryduetoitsreliability,featurerichness,andeaseofuse.PHPMailersupportsSMTP,providesdetailederrorhandling,allowssendingHTMLandplaintextemails,supportsattachments,andenhancessecurity.Foroptimalu

Best Practices for Dependency Injection in PHPBest Practices for Dependency Injection in PHPMay 08, 2025 am 12:21 AM

The reason for using Dependency Injection (DI) is that it promotes loose coupling, testability, and maintainability of the code. 1) Use constructor to inject dependencies, 2) Avoid using service locators, 3) Use dependency injection containers to manage dependencies, 4) Improve testability through injecting dependencies, 5) Avoid over-injection dependencies, 6) Consider the impact of DI on performance.

PHP performance tuning tips and tricksPHP performance tuning tips and tricksMay 08, 2025 am 12:20 AM

PHPperformancetuningiscrucialbecauseitenhancesspeedandefficiency,whicharevitalforwebapplications.1)CachingwithAPCureducesdatabaseloadandimprovesresponsetimes.2)Optimizingdatabasequeriesbyselectingnecessarycolumnsandusingindexingspeedsupdataretrieval.

PHP Email Security: Best Practices for Sending EmailsPHP Email Security: Best Practices for Sending EmailsMay 08, 2025 am 12:16 AM

ThebestpracticesforsendingemailssecurelyinPHPinclude:1)UsingsecureconfigurationswithSMTPandSTARTTLSencryption,2)Validatingandsanitizinginputstopreventinjectionattacks,3)EncryptingsensitivedatawithinemailsusingOpenSSL,4)Properlyhandlingemailheaderstoa

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

MantisBT

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

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool