lnmp vhost 虚拟目录配置

  以前常用Windows 很熟悉,lnmp 配置虚拟目录也很简单。

安装完lnmp环境之后,在nginx的配置文件夹下,我采用的方法是复制default.conf 然后重命名为vhost_a.conf 文件/vhost_b.conf

 

当然里面的root 网站目录要设置一下:

vhost_a.conf:

server {

    listen       80;

    server_name  b.caesar.com;



    #charset koi8-r;

    #access_log  /var/log/nginx/log/host.access.log  main;



    location / {

        root   /usr/share/nginx/html/b/;

        index  index.html index.htm index.php;

    }



    #error_page  404              /404.html;



    # redirect server error pages to the static page /50x.html

    #

    error_page   500 502 503 504  /50x.html;

    location = /50x.html {

        root   /usr/share/nginx/html/b;

    }



    # proxy the PHP scripts to Apache listening on 127.0.0.1:80

    #

    #location ~ \.php$ {

    #    proxy_pass   http://127.0.0.1;

    #}



    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

    #

    location ~ \.php$ {

        root            /usr/share/nginx/html/b;

        fastcgi_pass   127.0.0.1:9000;

        fastcgi_index  index.php;

        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

        include        fastcgi_params;

    }



    # deny access to .htaccess files, if Apache's document root

    # concurs with nginx's one

    #

    #location ~ /\.ht {

    #    deny  all;

    #}

}

vhost_b.conf:

server {

    listen       80;

    server_name  b.caesar.com;



    #charset koi8-r;

    #access_log  /var/log/nginx/log/host.access.log  main;



    location / {

        root   /usr/share/nginx/html/b/;

        index  index.html index.htm index.php;

    }



    #error_page  404              /404.html;



    # redirect server error pages to the static page /50x.html

    #

    error_page   500 502 503 504  /50x.html;

    location = /50x.html {

        root   /usr/share/nginx/html/b/;

    }



    # proxy the PHP scripts to Apache listening on 127.0.0.1:80

    #

    #location ~ \.php$ {

    #    proxy_pass   http://127.0.0.1;

    #}



    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

    #

    location ~ \.php$ {

        root            /usr/share/nginx/html/b/;

        fastcgi_pass   127.0.0.1:9000;

        fastcgi_index  index.php;

        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

        include        fastcgi_params;

    }



    # deny access to .htaccess files, if Apache's document root

    # concurs with nginx's one

    #

    #location ~ /\.ht {

    #    deny  all;

    #}

}

然后nginx.conf 默认加载conf.d 文件夹下的所有后缀名为.conf的文件。所以不用修改nginx.conf

include /etc/nginx/conf.d/*.conf;

然后修改服务器的hosts 文件,将域名添加进去。

vi /etc/hosts

然后在html 目录下创建你的 a,b 目录

然后~nginx重新加载配置文件,或者restart

/etc/init.d/nginx restart 

根据你服务器自己的配置进行重启,

然后如果域名是虚拟的病没有解析,注意要自己的电脑加上hosts

 

 

 



                                                                                                              

你可能感兴趣的:(host)