虚拟机配置本地域名访问

时间:2020-05-01

虚拟机

编辑 vim /etc/host

127.0.0.1 wyzda.cn
127.0.0.1 note.wyzda.cn
127.0.0.1 wyzda.com
127.0.0.1 smarty.com

nginx配置

server {
    listen 80;
    server_name wyzda.cn;
    location / {
        root 你的代码目录;
        index index.html index.htm index.php;
        if (!-e $request_filename) {
            rewrite ^/(.*)$ /index.php?s=$1 last;
            break;
        }
    }
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root html;
    }
    location ~ \.php$ {
        root html;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME 你的代码目录$fastcgi_script_name;
        include fastcgi_params;
    }
}

本机电脑

域名指向虚拟机IP

C:\Windows\System32\drivers\etc\hosts

192.168.1.100 wyzda.cn
192.168.1.100 note.wyzda.cn
192.168.1.100 wyzda.com
192.168.1.100 smarty.com