mac nginx的虚拟站点配置

 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;

}

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

 4、在/etc/hosts 里增加

   127.0.0.1   www.test.com

  5、sudo nginx -s reload 重启nginx

你可能感兴趣的:(mac nginx的虚拟站点配置)