如何在win 客戶端通過在瀏覽器中輸入域名訪問服務(wù)器呢状答?
虛擬主機(jī)類型有三種
- 基于域名主機(jī)類型(常見)
- 基于端口的虛擬主機(jī)
- 基于IP 的虛擬主機(jī)
基于域名的虛擬主機(jī)配置
配置基于域名虛擬機(jī)的nginx.conf 內(nèi)容
在/application/nginx/conf
目錄下修改nginx.conf 的內(nèi)容如下(修改配置文件之前習(xí)慣備份)柄错,
worker_processes 1;
events {
worker_connections 1024;
}
http {
server_names_hash_bucket_size 128;
include mime.types;
default_type application/octet-stream;
sendfile on;
}
server {
listen 80;
server_name www.etiantian.org;
location / {
root html/www;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
創(chuàng)建域名對應(yīng)的站點(diǎn)目錄及文件
[root@pdm1-centos6 ~]# mkdir /application/nginx/html/www -p
[root@pdm1-centos6 ~]# echo "http://www.etiantian.org" >/application/nginx/html/www/index.html
[root@pdm1-centos6 ~]# cat /application/nginx/html/www/index.html
http://www.etiantian.org
檢查語法并重新加載Nginx
- 先檢查Nginx 配置文件語法是否有錯誤:
[root@pdm1-centos6 ~]# /application/nginx/sbin/nginx -t
nginx: the configuration file /application/nginx-1.6.3//conf/nginx.conf syntax is ok
nginx: configuration file /application/nginx-1.6.3//conf/nginx.conf test is successful
- 重啟Nginx,前提是Nginx 已經(jīng)啟動污茵。
[root@pdm1-centos6 ~]# /application/nginx/sbin/nginx -s reload
## 啟動Nginx [root@pdm1-centos6 ~]# /application/nginx/sbin/nginx
## 如果沒有啟動Nginx 則無法reload
- 檢查Nginx 重啟的情況,查看端口與進(jìn)程是否OK
[root@pdm1-centos6 ~]# ps -ef|grep nginx
root 1162 1 0 10:09 ? 00:00:00 nginx: master process ../sbin/nginx
nginx 1216 1162 0 10:39 ? 00:00:00 nginx: worker process
root 1225 1128 0 10:43 pts/0 00:00:00 grep nginx
[root@pdm1-centos6 ~]# netstat -lntp|grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1162/nginx
- Linux 下測試域名站點(diǎn)配置的訪問結(jié)果:
[root@pdm1-centos6 ~]# echo "10.0.0.200 www.etiantian.org" >>/etc/hosts
[root@pdm1-centos6 ~]# tail -l /etc/hosts
10.0.0.200 www.etiantian.org
[root@pdm1-centos6 ~]# curl www.etiantian.org
http://www.etiantian.org
提示:不要忘記在訪問的客戶端做hosts 解析胳嘲,Linux 或者windows 都需要做hosts 解析温算。
- windows 下測試域名站點(diǎn)配置的訪問結(jié)果:
hosts 解析:在C:\Windows\System32\drivers\etc
這個路徑下找到hosts 文件,想辦法在后面追加10.0.0.200 www.etiantian.org
佳头。如果有權(quán)限的問題鹰贵,把文件復(fù)制到桌面,修改好了之后再復(fù)制回來康嘉,這個文件是沒有后綴的碉输。如果需要添加多個域名,在后面空格添加就行了亭珍。
配置好之后可以在dos 里ping 一下該域名敷钾。
C:\Users\Administrator>ping www.etiantian.org
正在 Ping www.etiantian.org [10.0.0.200] 具有 32 字節(jié)的數(shù)據(jù):
來自 10.0.0.200 的回復(fù): 字節(jié)=32 時間=535ms TTL=64
最后在瀏覽器中輸入http://www.etiantian.org/
,能訪問到如下頁面表示一切正常肄梨。
配置域名訪問服務(wù)器
配置多個域名
- 配置文件中添加多個server
- http 中添加域名個數(shù)與長度
- 文件路徑同上