mac 配置nginx 虚拟域名(转载)

我是通过homebrew 安装nginx 的,所以安装目录是默认的,之前多个server都是放在默认安装目录下的nginx.conf里的,但是这样不太好,就是会导致nginx.conf 越来越长,而且容易出现一些大括号缺失啥的类似的语法错误。看了下老大配的虚拟目录感觉不错,自己弄了下,成功了。好处是每个server 站点相互独立,互不影响,很简单,分享下过程~

    1、首先在nginx 的配置目录下:/usr/local/etc/nginx 新建一个文件夹sites,然后可以创建一个或多个配置文件例如nginx-test.conf。

    2、添加server的配置文件。

    server {
        listen       80;  //为了访问时不用写端口号,我把mac 的nginx监听端口改成80端口了
        server_name  www.test.com;
        index index.html index.htm index.php;
        root /Usrs/ad/www/tp5/public; #这是我测试的tp5安装目录
        location ~ .php$ {
                fastcgi_pass 127.0.0.1:9000; #/run/php/php5.6-fpm.sock
                fastcgi_index  index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
                try_files $uri = 404;
        }

        location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$
        {
                expires 30d;
        }
        location ~ .*.(js|css)?$
        {
                expires 1h;
        }

        ###this is to use open website lianjie like on apache##
        location / {
                if (!-e $request_filename) {
                        rewrite ^(.*)$ /index.php?s=$1 last;
                        break;
                }
        }
        ###end##
        access_log  /var/log/nginx/access/tp5.log main;

}

3、在配置文件nginx.conf http 下添加 include sites/nginx-*.conf.

 4、在/etc/hosts 里增加

   127.0.0.1   www.test.com

  5、sudo nginx -s reload 重启nginx 

  6、访问www.test.com 就可以看到tp5 页面的笑脸了,成功~
---------------------
作者:Dev_Meng
来源:CSDN
原文:https://blog.csdn.net/mengguihua110/article/details/79918612
版权声明:本文为博主原创文章,转载请附上博文链接!

原文地址:https://www.cnblogs.com/ampl/p/10842711.html