Nginx的基本配置文件
/usr/local/nginx/conf/nginx.conf
# 允许进程数量,建议设置为cpu核心数或者auto自动检测,注意Windows服务器上虽然可以启动多个processes,但是实际只会用其中一个
worker_processes 1;
events {
# 单个进程最大连接数(最大连接数=连接数*进程数)
# 根据硬件调整,和前面工作进程配合起来用,尽量大,但是别把cpu跑到100%就行。
worker_connections 1024;
}
http {
# 文件扩展名与文件类型映射表(是conf目录下的一个文件)
include mime.types;
# 默认文件类型,如果mime.types预先定义的类型没匹配上,默认使用二进制流的方式传输(没有的话直接让用户下载)
default_type application/octet-stream;
# sendfile指令指定nginx是否调用sendfile 函数(zero copy 方式)来输出文件,对于普通应用,必须设为on。如果用来进行下载等应用磁盘IO重负载应用,可设置为off,以平衡磁盘与网络IO处理速度。
sendfile on;
# 长连接超时时间,单位是秒
keepalive_timeout 65;
# 虚拟主机的配置
server {
#监听端口
listen 80;
#域名,可以有多个,用空格隔开
server_name localhost;
#配置根目录以及默认页面
location / {
root html;
index index.html index.htm;
}
#出错页面配置
error_page 500 502 503 504 /50x.html;
#/50x.html文件所在位置
location = /50x.html {
root html;
}
}
}
Nginx监听不同域名
Nginx的配置文件nginx.conf
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 orgcomcn.top;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server {
listen 80;
server_name admin.orgcomcn.top;
location / {
root html1;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
Nginx监听不同端口
Nginx的配置文件nginx.conf,监听端口阿里云服务器需要开启相应的端口,否则无法访问。
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 orgcomcn.top;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server {
listen 8888;
server_name orgcomcn.top;
location / {
root html1;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
补充
1、www 是指 二级域名解析,以百度为例,就是www.baidu.com;
2、@ 是指前面不带任何主机名的,指主域名解析,以百度为例,就是 baidu.com
3、* 是指泛解析,是指除已添加的解析记录以外的所有主机都以此为准,以百度为例,就是 12343.baidu.com。
泛域名在实际使用中作用是非常广泛的,比如实现无限二级域名功能,提供免费的url转发,在IDC部门实现自动分配免费网址,在大型企业中实现网址分类管理等等,都发挥了巨大的作用。