开发者社区> 问答> 正文

linux下nginx解析本地虚拟域名

配置yaf框架的时候,发现得配置一个虚拟域名。
于是在/etc/hosts增加了一个本地域名127.0.0.1 www.abc.com;
在nginx/config/vhost目录下增加一个虚拟主机文件'www.abc.com`;

server
        {
                listen 80;
                #listen [::]:80;
                server_name www.abc.com;
                index index.html index.htm index.php default.html default.htm default.php;
                root  /home/wwwroor/www.abc.com/public;

                include none.conf;
                #error_page   404   /404.html;
                location ~ [^/]\.php(/|$)
                        {
                                # comment try_files $uri =404; to enable pathinfo
                                try_files $uri =404;
                                fastcgi_pass  unix:/tmp/php-cgi.sock;
                                fastcgi_index index.php;
                                include fastcgi.conf;
                                #include pathinfo.conf;
                        }

                location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
                        {
                                expires      30d;
                        }

                location ~ .*\.(js|css)?$
                        {
                                expires      12h;
                        }

                access_log off;
        }

但是每次访问www.abc.com的时候,访问的都是wwwroot这个web根目录。
怎么让它进入/home/wwwroor/www.abc.com/public这个目录啊?

展开
收起
a123456678 2016-06-22 14:23:45 3142 0
1 条回答
写回答
取消 提交回答
  • 请确认你的配置文件 www.abc.com 是否已经成功加载,内容是否正确。判断的方法很简单,在这个配置文件中输入一个错误的内容, 然后执行 nginx -t。

    因为从题主的描述可以看出, www.abc.com 这个文件应该需要被 nginx 的主配置文件所引用的(include),并且应该是通过 wildcard 方式加载。这就有可能出现没有成功加载情况。

    请观察输出,例如:

    nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
    nginx: configuration file /etc/nginx/nginx.conf test is successful
    代表加载了配置文件 /etc/nginx/nginx.conf,并且没有错误。

    2019-07-17 19:45:31
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
域名大数据的应用 立即下载
“域”见更美好的未来——域名筑梦互联网+ 立即下载
“域”感——《域名投资从入门到精通》 立即下载

相关镜像