Table of contents
1. Minimum configuration
original configuration file
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#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;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
Minimal version with comments removed
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
worker_processes
worker_processes 1
;
the default is
1
, which means to open a business process
worker_connections
worker_connections 1024
;
the number of connections a single business process can accept
include mime.types;
include mime.types
;
import
http mime
types
default_type application/octet-stream;
default_type application/octet
-
stream
;
If
the mime
type does not match, it will be transmitted by binary stream by default.
sendfifile on;
sendfile on
;
use
linux
's
sendfile (socket, file, len)
for efficient network transmission, that is,
0
copy of data.
Sendfifile is not enabled
. At this time, after nginx copies the requested resources from the disk, it still needs to go through multiple copies to the network interface cache.
After it is turned on, only one signal is needed, read once
keepalive_timeout 65; The connection keeps the heartbeat time, which is divided into the client and the proxy side, which will be introduced later
server, a server can represent a host, so configuring multiple servers can have a polymorphic virtual host (vhost)
Virtual host configuration
server {
listen 80; 监听端口号
server_name localhost; 主机名
location / { 匹配路径
root html; 文件根目录
index index.html index.htm; 默认页名称
}
error_page 500 502 503 504 /50x.html; 报错编码对应页面
location = /50x.html {
root html;
}
}
Two, virtual host
Originally, a server can only correspond to one site, but through virtual host technology, it can be virtualized into multiple sites to provide external services at the same time
servername
matching rules
What we need to pay attention to is that
servername
is matched in order of priority, and it will not continue to match if it is written on the previous match.
complete match
We can
match multiple domain names in the same
servername
server_name vod.mmban.com www1.mmban.com;
wildcard match
server_name *.mmban.com
wildcard end match
server_name vod.*;
regular match
server_name ~^[0-9]+\.mmban\.com$;