在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,能正常打開,如圖:


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM