域名虛擬主機(jī):
[root@web01 /application/nginx/conf]# egrep -v "^$|#" nginx.conf.default >nginx.conf? ? #去掉空行和#號(hào)行
[root@web01 /application/nginx/conf]# cat -n nginx.conf? ? ? #查看
[root@web01 /application/nginx/conf]# vim nginx.conf? ? ? ? #編輯
set nu? ==>17行 4dd? ? #去掉17-21行嫌蚤,在server內(nèi)追加內(nèi)容
? ? 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? ? #沒目錄創(chuàng)建個(gè)主頁目錄
[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? ? #追加到環(huán)境變量
[root@web01 /application/nginx/conf]# . /etc/profile? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #執(zhí)行下它
[root@web01 /application/nginx/conf]# echo $PATH? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #查看顯示環(huán)境變量
/application/nginx/sbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin?
[root@web01 /application/nginx/conf]# /application/nginx/sbin/nginx? ? ? ? #全路徑啟動(dòng)
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
端口虛擬主機(jī):
[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虛擬主機(jī):
[root@web02 /application/nginx/conf]# ip addr add 10.0.0.9 dev eth0 label eth0:9? ? ? ? ? ? ? ? #加個(gè)網(wǎng)卡好像是虛擬的
[root@web02 /application/nginx/conf]# ip addr add 10.0.0.10 dev eth0 label eth0:10? ? ? ? ? ? ? #加個(gè)網(wǎng)卡
[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和端口號(hào)
? ? ? ? server_name? www.etiantian.org;
? ? ? ? location / {
? ? ? ? ? ? root? html/www;
? ? ? ? ? ? index? index.html index.htm;
? ? ? ? }
? ? }
? ? server {
? ? ? ? listen? ? ? 10.0.0.9:80;? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #追加IP和端口號(hào)
? ? ? ? server_name? bbs.etiantian.org;
? ? ? ? location / {
? ? ? ? ? ? root? html/bbs;
? ? ? ? ? ? index? index.html index.htm;
? ? ? ? }
? ? }
? ? server {
? ? ? ? listen? ? ? 10.0.0.10:80;? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #追加IP和端口號(hào)
? ? ? ? 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? ? ? ? ? #停止服務(wù)
[root@web02 /application/nginx/conf]# nginx? ? ? ? ? ? ? ? ? ? ? #啟動(dòng)服務(wù)
[root@web02 /application/nginx/conf]# nginx -s reload? ? ? #平滑
[root@web02 /application/nginx/conf]# curl 10.0.0.9? ? ? ? ? ? #測試完成
bbs.etiantian.org
惡意解析:
一:什么是惡意域名解析
? ? ? ? 一般情況下垦垂,要使域名能訪問到網(wǎng)站需要兩步,第一步劫拗,將域名解析到網(wǎng)站所在的主機(jī),第二步憔足,在web服務(wù)器中將域名與相應(yīng)的網(wǎng)站綁定酒繁。但是,如果通過主機(jī)IP能直接訪問某網(wǎng)站找蜜,那么把域名解析到這個(gè)IP也將能訪問到該網(wǎng)站稳析,而無需在主機(jī)上綁定,也就是說任何人將任何域名解析到這個(gè)IP就能訪問到這個(gè)網(wǎng)站诚纸。
二:惡意域名解析的危害
? ? ? ? 可能您并不介意通過別人的域名訪問到您的網(wǎng)站陈惰,但是如果這個(gè)域名是未備案域名呢?
? ? ? ? 假如那域名是不友善的域名井辆,比如曾經(jīng)指向非法網(wǎng)站,容易引發(fā)搜索引擎懲罰杯缺,連帶IP受到牽連萍肆。即使域名沒什么問題,但流量也會(huì)被劫持到別的域名塘揣,從而遭到廣告聯(lián)盟的封殺亲铡。
三;如何防止奴愉,配置里第一個(gè)標(biāo)簽如下配置
server{
listen 80;
server_name _default;
return 500;
}
優(yōu)化配置怎么分類
偶合性好锭硼,出問題就改單個(gè)模塊。類似分類
[root@web02 /application/nginx/conf]# mkdir extra? #建個(gè)放模塊的目錄
[root@web02 /application/nginx/conf]# sed -n '10,17p' nginx.conf >extra/01_www.conf? ? ? ? #追加進(jìn)模塊文件
[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? ? ? #把這幾個(gè)模塊文件放進(jìn)配置文件
[root@web02 /application/nginx/conf]# cat nginx.conf? ? ? #追加 log日志模塊轰异,按它這個(gè)格式或模式顯示暑始。
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/? ? ? ? #查看日志的地方