域名虚拟主机:
[root@web01 /application/nginx/conf]# egrep -v "^$|#" nginx.conf.default >nginx.conf #去掉空行和#号行
[root@web01 /application/nginx/conf]# cat -n nginx.conf #查看
[root@web01 /application/nginx/conf]# vim nginx.conf #编辑
set nu ==>17行 4dd #去掉17-21行,在server内追加内容
1 worker_processes 1;
2 events {
3 worker_connections 1024;
4 }
5 http {
6 include mime.types;
7 default_type application/octet-stream;
8 sendfile on;
9 keepalive_timeout 65;
10 server {
11 listen 80;
12 server_name ww.etiantian.org;
13 location / {
14 root html/www;
15 index index.html index.htm;
16 }
17 }
server {
11 listen 80;
12 server_name ww.etiantian.org;
13 location / {
14 root html/www;
15 index index.html index.htm;
16 }
17 }
18 }
[root@web01 /application/nginx/conf]# cat -n nginx.conf #查看
[root@web01 /application/nginx/conf]# mkdir ../html/www #没目录创建个主页目录
[root@web01 /application/nginx/conf]# echo "www.etiantian.org" >../html/www/index.html #追加到主页文件
[root@web01 /application/nginx/conf]# cat ../html/www/index.html #查看
www.etiantian.org
[root@web01 /application/nginx/conf]# cat /etc/hosts #查看
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
172.16.1.5 lb01
172.16.1.6 lb02
172.16.1.7 web01
172.16.1.8 web02
172.16.1.9 web03
172.16.1.31 nfs01
172.16.1.41 backup
172.16.1.51 db01 db01.etiantian.org
172.16.1.61 m01
[root@web01 /application/nginx/conf]# echo "10.0.0.7 www.etiantian.org" >>/etc/hosts #追加到解析文件
[root@web01 /application/nginx/conf]# tail -1 /etc/hosts #还是查看
10.0.0.7 www.etiantian.org
[root@web01 /application/nginx/conf]# ping www.etiantian.org #查下域名ping的通不
PING www.etiantian.org (10.0.0.7) 56(84) bytes of data.
64 bytes from www.etiantian.org (10.0.0.7): icmp_seq=1 ttl=64 time=0.014 ms
64 bytes from www.etiantian.org (10.0.0.7): icmp_seq=2 ttl=64 time=0.054 ms
64 bytes from www.etiantian.org (10.0.0.7): icmp_seq=3 ttl=64 time=0.054 ms
64 bytes from www.etiantian.org (10.0.0.7): icmp_seq=4 ttl=64 time=0.055 ms
^C
--- www.etiantian.org ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3000ms
rtt min/avg/max/mdev = 0.014/0.044/0.055/0.018 ms
[root@web01 /application/nginx/conf]# echo 'PATH="/application/nginx/sbin:$PATH"' >>/etc/profile #追加到环境变量
[root@web01 /application/nginx/conf]# . /etc/profile #执行下它
[root@web01 /application/nginx/conf]# echo $PATH #查看显示环境变量
/application/nginx/sbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@web01 /application/nginx/conf]# /application/nginx/sbin/nginx #全路径启动
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()
[root@web01 /application/nginx/conf]# nginx -t #检查语法
nginx: the configuration file /application/nginx-1.16.0//conf/nginx.conf syntax is ok
nginx: configuration file /application/nginx-1.16.0//conf/nginx.conf test is successful
[root@web01 /application/nginx/conf]# nginx -s reload #平滑重启
[root@web01 /application/nginx/conf]# ps -ef|grep nginx #查下端口
root 12599 1 0 09:11 ? 00:00:00 nginx: master process /application/nginx/sbin/nginx
www 12774 12599 0 09:36 ? 00:00:00 nginx: worker process
root 12779 6987 0 09:37 pts/0 00:00:00 grep --color=auto nginx
[root@web01 /application/nginx/conf]# curl www.etiantian.org #测试下域名成功没
www.etiantian.org
端口虚拟主机:
[root@web01 /application/nginx/conf]# cat 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 www.etiantian.org;
location / {
root html/www;
index index.html index.htm;
}
}
server {
listen 81;
server_name bbs.etiantian.org;
location / {
root html/bbs;
index index.html index.htm;
}
}
server {
listen 82;
server_name blog.etiantian.org;
location / {
root html/blog;
index index.html index.htm;
}
}
}
[root@web01 /application/nginx/conf]# nginx -s reload #平滑重启
[root@web01 /application/nginx/conf]# netstat -lntup|grep nginx #查看端品
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 12599/nginx: master
tcp 0 0 0.0.0.0:81 0.0.0.0:* LISTEN 12599/nginx: master
tcp 0 0 0.0.0.0:82 0.0.0.0:* LISTEN 12599/nginx: master
[root@web01 /application/nginx/conf]# curl bbs.etiantian.org:81 #测试
bbs.etiantian.org
[root@web01 /application/nginx/conf]# curl bbs.etiantian.org:82
blog.etiantian.org
IP虚拟主机:
[root@web02 /application/nginx/conf]# ip addr add 10.0.0.9 dev eth0 label eth0:9 #加个网卡好像是虚拟的
[root@web02 /application/nginx/conf]# ip addr add 10.0.0.10 dev eth0 label eth0:10 #加个网卡
[root@web02 /application/nginx/conf]# ifconfig #查看
[root@web02 /application/nginx/conf]# vim nginx.conf #编辑配置文件
[root@web02 /application/nginx/conf]# cat 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 10.0.0.8:80; #追加IP和端口号
server_name www.etiantian.org;
location / {
root html/www;
index index.html index.htm;
}
}
server {
listen 10.0.0.9:80; #追加IP和端口号
server_name bbs.etiantian.org;
location / {
root html/bbs;
index index.html index.htm;
}
}
server {
listen 10.0.0.10:80; #追加IP和端口号
server_name blog.etiantian.org;
location / {
root html/blog;
index index.html index.htm;
}
}
}
[root@web02 /application/nginx/conf]# nginx -t #测试语法
[root@web02 /application/nginx/conf]# nginx -s stop #停止服务
[root@web02 /application/nginx/conf]# nginx #启动服务
[root@web02 /application/nginx/conf]# nginx -s reload #平滑
[root@web02 /application/nginx/conf]# curl 10.0.0.9 #测试完成
bbs.etiantian.org
恶意解析:
一:什么是恶意域名解析
一般情况下,要使域名能访问到网站需要两步,第一步,将域名解析到网站所在的主机,第二步,在web服务器中将域名与相应的网站绑定。但是,如果通过主机IP能直接访问某网站,那么把域名解析到这个IP也将能访问到该网站,而无需在主机上绑定,也就是说任何人将任何域名解析到这个IP就能访问到这个网站。
二:恶意域名解析的危害
可能您并不介意通过别人的域名访问到您的网站,但是如果这个域名是未备案域名呢?
假如那域名是不友善的域名,比如曾经指向非法网站,容易引发搜索引擎惩罚,连带IP受到牵连。即使域名没什么问题,但流量也会被劫持到别的域名,从而遭到广告联盟的封杀。
三;如何防止,配置里第一个标签如下配置
server{
listen 80;
server_name _default;
return 500;
}
优化配置怎么分类
偶合性好,出问题就改单个模块。类似分类
[root@web02 /application/nginx/conf]# mkdir extra #建个放模块的目录
[root@web02 /application/nginx/conf]# sed -n '10,17p' nginx.conf >extra/01_www.conf #追加进模块文件
[root@web02 /application/nginx/conf]# sed -n '18,25p' nginx.conf >extra/02_bbs.conf
[root@web02 /application/nginx/conf]# sed -n '26,33p' nginx.conf >extra/03_blog.conf
[root@web02 /application/nginx/conf]# sed -i '10 i include extra/01_www.conf;\ninclude extra/02_bbs.conf;\ninclude extra/03_blog.conf;' nginx.conf #把这几个模块文件放进配置文件
[root@web02 /application/nginx/conf]# cat nginx.conf #追加 log日志模块,按它这个格式或模式显示。
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
log_format main '$remote_addr - $remote_user [$time_local] "$request" ' #追加log日志模块
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
include extra/01_www.conf;
include extra/02_bbs.conf;
include extra/03_blog.conf;
include extra/04_status.conf;
}
[root@web02 /application/nginx/conf]# cat extra/01_www.conf #追加访问日志的模块
server {
listen 80;
server_name www.etiantian.org;
location / {
root html/www;
index index.html index.htm;
}
access_log logs/access_www.log main; #追加访问日志的模块
}
[root@web02 /application/nginx/conf]# ll ../logs/ #查看日志的地方