分享

配置在 windows 客户端浏览器通过域名访问服务器

 昵称48509425 2018-05-27

  1. 如何在win 客户端通过在浏览器中输入域名访问服务器呢?

虚拟主机类型有三种

    1. 基于域名主机类型(常见)
    2. 基于端口的虚拟主机
    3. 基于IP 的虚拟主机
基于域名的虚拟主机配置

  1. 配置基于域名虚拟机的nginx.conf 内容
    在/application/nginx/conf目录下修改nginx.conf 的内容如下(修改配置文件之前习惯备份)

    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.; location / { root html/www; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } }

     
    创建域名对应的站点目录及文件

    [root@pdm1-centos6 ~]# mkdir /application/nginx/html/www -p [root@pdm1-centos6 ~]# echo "http://www." >/application/nginx/html/www/index.html [root@pdm1-centos6 ~]# cat /application/nginx/html/www/index.html http://www.

     
    检查语法并重新加载Nginx
    1. 先检查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

     
    1. 重启Nginx,前提是Nginx 已经启动。

    [root@pdm1-centos6 ~]# /application/nginx/sbin/nginx -s reload ## 启动Nginx [root@pdm1-centos6 ~]# /application/nginx/sbin/nginx ## 如果没有启动Nginx 则无法reload

     
    1. 检查Nginx 重启的情况,查看端口与进程是否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

     
    1. Linux 下测试域名站点配置的访问结果:

    [root@pdm1-centos6 ~]# echo "10.0.0.200 www." >>/etc/hosts [root@pdm1-centos6 ~]# tail -l /etc/hosts 10.0.0.200 www. [root@pdm1-centos6 ~]# curl www. http://www.

     

    提示:不要忘记在访问的客户端做hosts 解析,Linux 或者windows 都需要做hosts 解析。

    1. windows 下测试域名站点配置的访问结果:

    hosts 解析:在C:\Windows\System32\drivers\etc这个路径下找到hosts 文件,想办法在后面追加10.0.0.200 www.。如果有权限的问题,把文件复制到桌面,修改好了之后再复制回来,这个文件是没有后缀的。如果需要添加多个域名,在后面空格添加就行了。

    配置好之后可以在dos 里ping 一下该域名。

    C:\Users\Administrator>ping www. 正在 Ping www. [10.0.0.200] 具有 32 字节的数据: 来自 10.0.0.200 的回复: 字节=32 时间=535ms TTL=64

     

    最后在浏览器中输入http://www./ ,能访问到如下页面表示一切正常。


    配置多个域名

    1. 配置文件中添加多个server
    2. http 中添加域名个数与长度
    3. 文件路径同上

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多