_for nod send nop request user 模式 -s hit
main 配置段:
user nginx; #指定用于运行 worker 进程的用户和组
worker_processes 4; #worker 的进程数;通常应该为 CPU 的核心数或核心数减 1
worker_cpu_affinity 0001 0010 0100 1000; 进程绑定在 CPU 上的指定核上
error_log /var/log/nginx/error.log; #错误日志存放路径
pid /run/nginx.pid; #nginx 运行进程路径
worker_rlimit_nofile 51200; #单个 worker 进程所能够打开的最大文件数量
daemon on; #是否以守护进程方式启动 nginx 进程
events 配置段:
events {
worker_connections 50000; #每个 worker 进程所能够打开的最大并发连接数量; 但是不能大于 worker_rlimit_nofile 数量
use epoll; #指明并发连接请求的处理方法
accept_mutex on; #是否打开负载均衡锁,处理新的连接请求的方法; on 意味着由 worker 轮流处理新请求,off 意味着每个新请求的到达都会通知 worker 进程.默认需要开启
}
http 配置段:包含 server 配置段,其 server 配置段也可以放置于 / etc/nignx/conf.d / 目录下
http {
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 /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
include /etc/nginx/conf.d/*.conf;
}
server 配置段:可以再主配置文件 / etc/nginx/nginx.conf 中的 http 中配置,也可以在 / erc/nginx/conf.d / 分别创建自己的 conf 文件.
1,先在 Nginx 的默认路径下创建三个目录, 也可以在其他指定路径下存放 html 文件:
mkdir /usr/share/nginx/{yuming,port,IP}
mkdir -p /lufei/root/{yuming,port,IP}
2,分别在各自的路径下面写入如下 index.html 的文件
域名网页:
基于域名的虚拟主机 - lufei-yuming
www.lufei-yuming.com
Port 网页
基于端口的虚拟主机 - lufei-port
www.lufei-port.com
IP 网页
基于 IP 的虚拟主机 - lufei-IP
www.lufei-IP.com
说明:当服务器都配置完成后,需要在本地主机上做地址和域名解析
01,以 win10 为例
C:\WINDOWS\system32\drivers\etc 路径下的 hosts 文件添加如下内容:192.168.1.72 www.lufei.com
02,若要在 Linux 中访问:
在 / etc/hosts 中配置 192.168.1.72 www.lufei.com
3,基于域名的配置:在 / etc/nginx/conf.d / 下创建一个文件 yuming.conf,配置完成后 nginx -s reload 重新加载
server {
listen 80; #监听端口 80
server_name www.lufei.com *.lufei.com lufei.com *.lufei.*; #域名的配置,其书写格式可以使用正则表达式.
location / {
#root /lufei/root/yuming; #根目录的的绝对路径配置
root yuming; # 相对路径,相对 nginx 根目录.nginx 的默认路径:/usr/share/nginx(yum 安装方式的)
index index.html; #默认主文件.默认跳转到 index.html 页面
}
}
访问测试:
[root@localhost yuming]# curl www.lufei.com
基于域名的虚拟主机 - lufei-yuming
www.lufei-yuming.com
4,基于 port 的配置:在 / etc/nginx/conf.d / 下创建一个文件 port.conf,配置完成后 nginx -s reload 重新加载
[root@localhost yuming]# cat /etc/nginx/conf.d/port.conf
server {
listen 2225; #监听端口 2225
server_name www.lufei.com *.lufei.com lufei.com *.lufei.*; #域名的配置,其书写格式可以使用正则表达式.
location / {
#root /lufei/root/port; #根目录的的绝对路径配置
root port; # 相对路径,相对 nginx 根目录.nginx 的默认路径:/usr/share/nginx(yum 安装方式的)
index index.html; #默认主文件.默认跳转到 index.html 页面
}
}
访问测试:
[root@localhost yuming]# curl www.lufei.com:2225
基于端口的虚拟主机 - lufei-port
www.lufei-port.com
5,基于 IP 的配置:在 / etc/nginx/conf.d / 下创建一个文件 IP.conf ,配置完成后 nginx -s reload 重新加载
server {
listen 80; #监听端口 80
server_name 192.168.1.72; #域名的配置,其书写格式可以使用正则表达式.
location / {
#root /lufei/root/IP; 根目录的的绝对路径配置
root IP; # 相对路径,相对 nginx 根目录.nginx 的默认路径:/usr/share/nginx(yum 安装方式的)
index index.html; #默认主文件.默认跳转到 index.html 页面
}
}
访问测试:
[root@localhost yuming]# curl 192.168.1.72
基于 IP 的虚拟主机 - lufei-IP
www.lufei-IP.com
nginx 虚拟主机三种模式的简单实现
来源: http://www.bubuko.com/infodetail-2465856.html