This article mainly shares with you how to configure nginx file sample code, I hope it can help you.
nginx.conf
user www www; # Nginx的worker进程运行用户以及用户组worker_processes 4; # 启动进程数,通常设置成和cpu的数量相等#worker_processes auto;#以下参数指定了哪个cpu分配给哪个进程,一般来说不用特殊指定。如果一定要设的话,用0和1指定分配方式.#这样设就是给1-4个进程分配单独的核来运行,出现第5个进程是就是随机分配了。#worker_processes 4 #4核CPU #worker_cpu_affinity 0001 0010 0100 1000error_log /home/wwwlogs/nginx_error.log crit; # 定义全局错误日志定义类型,[debug|info|notice|warn|crit]pid /usr/local/nginx/logs/nginx.pid; # PID文件#Specifies the value for maximum file descriptors that can be opened by this process.# 一个nginx进程打开的最多文件描述符数目,理论值应该是最多打开文件数(ulimit -n)与nginx进程数相除,但是nginx分配请求并不是那么均匀,所以最好与ulimit -n的值保持一致。worker_rlimit_nofile 51200;# 工作模式及连接数上限events { # use [ kqueue | rtsig | epoll | /dev/poll | select | poll ]; epoll模型是Linux 2.6以上版本内核中的高性能网络I/O模型,如果跑在FreeBSD上面,就用kqueue模型。 use epoll; worker_connections 51200; # 单个后台worker process进程的最大并发链接数 #worker工作方式:串行(一定程度降低负载,但服务器吞吐量大时,关闭使用并行方式) multi_accept on; } http { #文件扩展名与文件类型映射表 include mime.types; #默认文件类型 default_type application/octet-stream; 服务器名字的hash表大小 server_names_hash_bucket_size 128; #指定来自客户端请求头的hearerbuffer大小 client_header_buffer_size 32k; #指定客户端请求中较大的消息头的缓存最大数量和大小。 large_client_header_buffers 4 32k; #客户端请求单个文件的最大字节数 client_max_body_size 50m; sendfile on; #开启高效传输模式。 #防止网络阻塞 tcp_nopush on; keepalive_timeout 60; # 连接超时时间 ,单位是秒 tcp_nodelay on; #FastCGI相关参数是为了改善网站的性能:减少资源占用,提高访问速度。 fastcgi_connect_timeout 300; fastcgi_send_timeout 300; fastcgi_read_timeout 300; fastcgi_buffer_size 64k; fastcgi_buffers 4 64k; fastcgi_busy_buffers_size 128k; fastcgi_temp_file_write_size 256k; gzip on; # 开启gzip压缩 gzip_min_length 1k; #最小压缩文件大小 gzip_buffers 4 16k; #压缩缓冲区 gzip_http_version 1.1; #压缩版本(默认1.1,前端如果是squid2.5请使用1.0) gzip_comp_level 2; #压缩等级 1-9 等级越高,压缩效果越好,节约宽带,但CPU消耗大 gzip_types text/plain application/javascript application/x-javascript text/javascript text/css application/xml application/xml+rss; #压缩类型,默认就已经包含text/html,所以下面就不用再写了,写上去也不会有问题,但是会有一个warn。 #前端缓存服务器缓存经过压缩的页面 gzip_vary on; gzip_proxied expired no-cache no-store private auth; gzip_disable "MSIE [1-6]\."; #limit_conn_zone $binary_remote_addr zone=perip:10m; ##If enable limit_conn_zone,add "limit_conn perip 10;" to server section. server_tokens off; access_log off; # 定义日志格式 log_format up_head '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for" "deviceid: $http_deviceid"' '"$request_body" $upstream_response_time "$request_time"'; include vhost/*.conf; }
vhost/test.conf
server { listen 80; listen 443 ssl; server_name www.test.com; ssl_certificate /nginx/conf/https/www.test.com.crt; ssl_certificate_key /nginx/conf/https/www.test.com.key; root /www/www.test.com; index index.html index.htm index.php; location ~^/test.php { default_type application/json; return 404 '{404}'; access_log off; } location ~ ^/test/status(.*)$ { default_type text/html; access_log /log/nginx/access/dot.log; return 200 ''; } location / { try_files $uri $uri/ /index.php?$query_string; } location ~\.php$ { # 如果用到 sock 则值参考 unix:/var/run/php/php7.0-fpm.sock fastcgi_pass unix:/tmp/php-cgi.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; access_log /log/nginx/access/access.log up_head; } #静态文件 location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 30d; } location ~ .*\.(js|css)?$ { expires 12h; } location ~ /.well-known { allow all; } location ~ /\. { deny all; } error_log /log/nginx/error/error.log; }
Definition of log format parameters:
#定义日志的格式。后面定义要输出的内容。 #1.$remote_addr 与$http_x_forwarded_for 用以记录客户端的ip地址; #2.$remote_user :用来记录客户端用户名称; #3.$time_local :用来记录访问时间与时区; #4.$request :用来记录请求的url与http协议; #5.$status :用来记录请求状态; #6.$body_bytes_sent :记录发送给客户端文件主体内容大小; #7.$http_referer :用来记录从那个页面链接访问过来的; #8.$http_user_agent :记录客户端浏览器的相关信息
Related recommendations:
Detailed explanation of Nginx configuration file nginx.conf
Detailed explanation of Nginx configuration file example
Simple description of Nginx configuration file
The above is the detailed content of nginx how to configure file example. For more information, please follow other related articles on the PHP Chinese website!

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python are both high-level programming languages that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.


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

SublimeText3 Linux new version
SublimeText3 Linux latest version

Dreamweaver Mac version
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

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