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