一個域名,對應一個IP地址
經過DNS域名解析服務器,能夠將域名解析爲IP地址html
這裏
經過修改host文件,指定域名的IP地址nginx
host劫持
是指在host文件中,配置域名和IP地址,當訪問域名的時候
由於,host文件中已經有了域名所對應的IP地址
因此,再也不須要訪問DNS服務器進行解析,直接訪問對應的IP地址vim
host文件的位置
C:\Windows\System32\drivers\etc服務器
Nginx配置文件註釋:app
[root@localhost conf]# vim nginx.conf worker_processes 1; #worker進程的數量 events { #事件塊的開始 worker_connections 1024; #每一個worker進程支持的最大鏈接數 } #事件塊的結束 http { #HTTP區塊的開始 include mime.types; #Nginx支持媒體類型庫文件 default_type application/octet-stream; #默認的媒體類型 sendfile on; #開啓高速傳輸模式 keepalive_timeout 65; #鏈接超時 server { #第一個server區塊的開始 listen 80; #提供服務的端口,默認爲80 server_name www.nautilus.org ; #提供服務的域名主機 location / { #第一個location區塊的開始 root html/www; #站點的根目錄,至關於Nginx的安裝目錄 index index.html index.htm; #默認的首頁文件,多個使用空格隔開 } #第一個location區塊的結束 error_page 500 502 503 504 /50x.html; #出現對應的http狀態碼是,使用50x.html迴應客戶 location = /50x.html { #location區塊的開始,訪問50x.html root html; #指定對應的站點目錄爲html } } } #HTTP區塊的結束
操做步驟dom
[root@localhost nginx]# ls client_body_temp fastcgi_temp logs sbin uwsgi_temp conf html proxy_temp scgi_temp [root@localhost nginx]# cd html [root@localhost html]# [root@localhost html]# mkdir www [root@localhost html]# [root@localhost html]# cd www [root@localhost www]# ls index.html [root@localhost www]# vim index.html hello localhost [root@localhost nginx]# vim /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 172.31.1.32 www.nautilus.org
訪問網站:ide
www.nautilus.org
Nginx配置基於多域名網站
server { listen 80; server_name www.nautilus.org; location / { root html/www; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } server { listen 80; server_name bbs.nautilus.org; location / { root html/bss; index index.html index.htm; } } server { listen 80; server_name blog.nautilus.org; location / { root html/blog; index index.html index.html; } } [root@localhost nginx]# cd html [root@localhost html]# [root@localhost html]# mkdir bbs [root@localhost html]# [root@localhost html]# cd bbs [root@localhost bbs]# ls index.html [root@localhost bbs]# vim index.html hello bbs [root@localhost html]# mkdir blog [root@localhost html]# [root@localhost html]# cd blog [root@localhost blog]# ls index.html [root@localhost blog]# vim index.html hello blog [root@localhost html]# ls 50x.html bbs blog index.html www [root@localhost nginx]# vim /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 172.31.1.32 www.nautilus.org 172.31.1.32 bbs.nautilus.org 172.31.1.32 blog.nautilus.org
訪問網站:code
www.nautilus.org bbs.nautilus.org blog.nautilus.org