在vmware虚拟机中如何配置本地域名并实现访问

在vmware虚拟机中配置本地域名并实现访问,分为三步:

一、编辑本机中的hosts文件

1、打开我的电脑,进入本地磁盘C:\Windows\System32\drivers\etc,如图:

 

2、找到hosts文件并用记事本打开,添加域名以及ip地址,如图:

二、编辑虚拟机中的hosts文件

1、首先用xshell连接服务器,如图

 

2、接着,我们打开虚拟机中的hosts文件。

[root@localhost ~]# vi /etc/hosts

在打开的hosts文件中,按“i”进入编辑模式,在编辑状态下,添加域名以及ip地址,如图

三、配置HTTP服务

1、编辑nginx配置文件

[root@localhost ~]# vi /etc/nginx/nginx.conf

2、在nginx配置文件配置HTTP服务,示例:

    server {
        listen 80;
        server_name ct.sdk.com;

        location / {
            root           /home/www/p2y9ysdk_svr/www;
            index index.php index.html index.htm;
        }

        location ~ .php$ {
            root           /home/www/p2y9ysdk_svr/www;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

    }

    server {
        listen 80;
        server_name ct.website.com;

        location / {
            root           /home/www/p2y9y_website/www;
            index index.php index.html index.htm;
        }

        location ~ .php$ {
            root           /home/www/p2y9y_website/www;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

    }

四、重启web服务器nginx

[root@localhost ~]# service nginx restart

访问域名http://ct.sdk.com,能正常打开,如图:

posted @ 2021-07-01 15:08  人可永真  阅读(3377)  评论(0编辑  收藏  举报