开发者社区> 问答> 正文

关于nginx的vhost.map

之前用的apache 在httpd/conf/vhost.map 直接这样配置就好了


---------------------

www.a.com /website/a
a.com /website/a

www.b.com /website/b
b.com /website/b

www.c.com /website/c
c.com /website/c


--------------------


nginx有类似这样的弄法么?就也是在一个文件里配置所有站点的,搜到有其他教程,是一个站点弄一个配置文件的,有点麻烦。。。

展开
收起
2016-06-18 04:10:43 5853 0
2 条回答
写回答
取消 提交回答
  • 旺旺:nectar2。
    楼主您好,

    apache里使用VirtualHost来配置虚拟主机,在nginx,应该是您上边做的,用Server Blocks来设置。

    可参考: https://www.nginx.com/resources/wiki/start/topics/examples/server_blocks/#
    2016-06-19 10:47:45
    赞同 展开评论 打赏
  • Re关于nginx的vhost.map
    user  www ftp;


    worker_processes 4;


    error_log  /website/logs/nginx_error.log  crit;


    pid        /usr/local/nginx/logs/nginx.pid;


    #Specifies the value for maximum file descriptors that can be opened by this process.
    worker_rlimit_nofile 51200;


    events
        {
            use epoll;
            worker_connections 51200;
        }


    http
        {
            include       mime.types;
            default_type  application/octet-stream;


            server_names_hash_bucket_size 128;
            client_header_buffer_size 32k;
            large_client_header_buffers 4 32k;
            client_max_body_size 60m;
                    server_tokens off;
            sendfile on;
            tcp_nopush     on;


            keepalive_timeout 60;


            tcp_nodelay on;


            fastcgi_connect_timeout 300;
            fastcgi_send_timeout 300;
            fastcgi_read_timeout 300;
            fastcgi_buffer_size 64k;
            fastcgi_buffers 4 64k;
            fastcgi_busy_buffers_size 128k;
            fastcgi_temp_file_write_size 256k;


            gzip on;
            gzip_min_length  1k;
            gzip_buffers     4 16k;
            gzip_http_version 1.0;
            gzip_comp_level 2;
            gzip_types       text/plain application/x-javascript text/css application/xml;
            gzip_vary on;


            #limit_zone  crawler  $binary_remote_addr  10m;
            log_format  access  '$remote_addr - $remote_user [$time_local] "$request" '
                 '$status $body_bytes_sent "$http_referer" '
                 '"$http_user_agent" $http_x_forwarded_for';




    server
        {
            listen       80;
            server_name localhost;
            index index.html index.htm index.php;
            root  /website;


            location ~ .*\.(php|php5)?$
                {
                    fastcgi_pass  unix:/tmp/php-cgi.sock;
                    fastcgi_index index.php;
                    include fcgi.conf;
                }


            location /status {
                stub_status on;
                access_log   off;
            }


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


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



            access_log  /website/logs/access.log  access;
        }






    #a.com
    server
        {
            listen       80;
            server_name a.com www.a.com;
            index index.html index.htm index.php;
            root  /website/a;


            location ~ .*\.(php|php5)?$
                {
                    fastcgi_pass  unix:/tmp/php-cgi.sock;
                    fastcgi_index index.php;
                    include fcgi.conf;
                }


            location /status {
                stub_status on;
                access_log   off;
            }


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


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


            
            access_log  /website/logs/a-access.log  access;
        }






    #b.com
    server
        {
            listen       80;
            server_name b.com www. b.com ;
            index index.html index.htm index.php;
            root  /website/b;


            location ~ .*\.(php|php5)?$
                {
                    fastcgi_pass  unix:/tmp/php-cgi.sock;
                    fastcgi_index index.php;
                    include fcgi.conf;
                }


            location /status {
                stub_status on;
                access_log   off;
            }


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


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


            
            access_log  /website/logs/b-access.log  access;
        }




    }




    /usr/local/nginx/conf/nginx.conf


    自己搞定了。。
    2016-06-18 08:03:53
    赞同 展开评论 打赏
问答标签:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
《Nginx 代理系统常用手册》 立即下载
CentOS Nginx PHP JAVA 多语言镜像使用手 立即下载
CentOS Nginx PHP JAVA多语言镜像使用手册 立即下载