Ubuntu 配置多域名站点

思路 -- 跟Windows 一样

1添加Nginx 指向项目的入口 配置域名

2修改本地host文件域名指向

实现:

1 进入Nginx 配置文件  默认地址为 

/etc/nginx/sites-enabled/

拷贝 default 文件一份 修改内容如下:(一个server就是一个域名配置)

server {
    listen 80; #端口
    root /home/frings/Work/basic/web; #指向项目入口文件
    index index.html index.htm index.nginx-debian.html index.php;

    server_name basic.com;#域名自己设置

    location / {
        try_files $uri $uri/ =404;
    }
        location ~ .+\.php($|/) {
                set $script $uri;
                set $path_info "/";
                if ($uri ~ "^(.+\.php)(/.+)") {
                        set $script $1;
                        set $path_info $2;
                }
                fastcgi_pass unix:/run/php/php7.0-fpm.sock;
                include /etc/nginx/fastcgi_params;
                fastcgi_param PATH_INFO $path_info;
                fastcgi_param SCRIPT_FILENAME $document_root/$script;
                fastcgi_param SCRIPT_NAME $script;
        }
}


server {
    listen 80;
    root /home/frings/Work/basic/web;
    index index.html index.htm index.nginx-debian.html index.php;

    server_name basic1.com;

    location / {
        try_files $uri $uri/ =404;
    }
        location ~ .+\.php($|/) {
                set $script $uri;
                set $path_info "/";
                if ($uri ~ "^(.+\.php)(/.+)") {
                        set $script $1;
                        set $path_info $2;
                }
                fastcgi_pass unix:/run/php/php7.0-fpm.sock;
                include /etc/nginx/fastcgi_params;
                fastcgi_param PATH_INFO $path_info;
                fastcgi_param SCRIPT_FILENAME $document_root/$script;
                fastcgi_param SCRIPT_NAME $script;
        }
}

2 修改host 域名指向 地址 /etc/hosts   (注意后面有s)

127.0.0.1    localhost 
127.0.1.1    ubuntu
127.0.0.1    basic.com #域名名称
127.0.0.1    basic1.com

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
0.0.0.0 account.jetbrains.com

 

posted @ 2018-12-08 15:27  鲜花满月楼  阅读(1337)  评论(0编辑  收藏  举报