Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

3. Sample Nginx configuration file

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

User www-data; # running user

Worker_processes 4 Bing # starts the process, usually set to equal the number of cpu

Error_log / var/log/nginx/error.log;# global error log and PID file

Pid / var/run/nginx.pid

# working mode and upper limit of connections

Events {

Use epoll; # epoll is a way of multiplexing IO (I _ Multiplexing O Multiplexing), but only for kernels above linux2.6, it can improve the performance of nginx.

Worker_connections 1024 cross # maximum number of concurrent links for a single background worker process process

Multi_accept on

}

# configure the http server and use its reverse proxy function to provide load balancing support

Http {

Include / etc/nginx/mime.types; # sets the mime type, which is defined by the mime.type file

Default_type application/octet-stream; # set log format

Access_log / var/log/nginx/access.log

Sendfile on

The # sendfile instruction specifies whether nginx calls the sendfile function (zero copy mode) to output files. For ordinary applications, it must be set to on. If it is used for downloading and other application disk IO heavy-load applications, it can be set to off to balance the processing speed of disk and network Ion O and reduce the system uptime.

# tcp_nopush on; # connection timeout

Keepalive_timeout 65

Tcp_nodelay on

# enable gzip compression

Gzip on

Gzip_disable "MSIE [1-6]\. (?!. * SV1)"

# set request buffer

Client_header_buffer_size 1k

Large_client_header_buffers 4 4k

Include / etc/nginx/conf.d/*.conf

Include / etc/nginx/sites-enabled/*

# set the list of servers for load balancer

Upstream mysvr {

Server 192.168.8.1:80 max_fails=1 fail_timeout=10s weight=1

Server 192.168.8.2:80 max_fails=1 fail_timeout=10s weight=1

Server 192.168.8.3:80 max_fails=1 fail_timeout=10s weight=10

The # weigth parameter represents the weight. The higher the weight, the greater the probability of being assigned.

The # max_fails parameter sets the number of failed attempts by Nginx to communicate with the server.

The # fail_timeout parameter sets the time period during which the server is considered unavailable and the time period for counting the number of failed attempts. The default is 10 seconds.

}

Server {

Listen 80T # listening on port 80

Server_name www.xx.com; # defines access using www.xx.com

Access_log logs/www.xx.com.access.log main; # set the access log of this virtual host

# default request

Location / {

Root / root; # defines the default site root location for the server

Index index.php index.html index.htm; # defines the name of the home index file

}

# define error prompt page

Error_page 500 502 503 504 / 50x.html

Location = / 50x.html {

Root / root

}

# static files, handled by nginx itself

Location ~ ^ / (p_w_picpaths | javascript | js | css | flash | media | static) / {

Root / var/www/virtual/htdocs

Expires 30d; # 30 days after expiration, static files are not updated very often. Expiration can be set to a larger size, or smaller if updated frequently.

}

# PHP script requests are all forwarded to FastCGI for processing. Use the default configuration of FastCGI.

Location ~\ .php$ {

Root / root

Fastcgi_pass 127.0.0.1:9000

Fastcgi_index index.php

Fastcgi_param SCRIPT_FILENAME / home/www/www$fastcgi_script_name

Include fastcgi_params

}

# set the address to view the status of Nginx

Location / NginxStatus {

Stub_status on

Access_log on

Auth_basic "NginxStatus"

Auth_basic_user_file conf/htpasswd

}

# prohibit access to .htxxx files

Location ~ /\ .ht {

Deny all

}

}

}

# configuration of reverse proxy

Location / {

Root / root; # defines the default site root location for the server

Index index.php index.html index.htm; # defines the name of the home index file

Proxy_pass http://numbergp; # request goes to the server list defined by numbergp

Proxy_set_header Host $host

Proxy_set_header X-Real-IP $remote_addr

Proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for

Client_max_body_size 10m; # the maximum number of bytes per file that the client is allowed to request

Client_body_buffer_size 128k; # buffer proxy buffers maximum number of bytes requested by the client

Proxy_connect_timeout 90; # nginx connection timeout with backend server (proxy connection timeout)

Proxy_send_timeout 90; # backend server data return time (proxy send timeout)

Proxy_read_timeout 90; # response time of back-end server after successful connection (proxy received timeout)

Proxy_buffer_size 4k; # sets the buffer size of the proxy server (nginx) for storing account information

Proxy_buffers 4 32k; # proxy_buffers buffer, if the average page size is less than 32k, set it like this

Proxy_busy_buffers_size 64k; # buffer size under high load (proxy_buffers*2)

Proxy_temp_file_write_size 64k; # sets the cache folder size. If it is larger than this value, it will be passed from the upstream server.

}

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report