首页 > 其他 > 详细

nginx虚拟主机

时间:2018-06-29 13:49:51      阅读:198      评论:0      收藏:0      [点我收藏+]

1 需求

一台服务器的nginx上如果需要运营多个网站,或者把二级域名拆分成不同的web映射目录。就需要使用vhost。web client上请求不同的域名,nginx会根据vhost里的server conf加载不同的配置。

 

2 配置

conf/nginx.conf

不需要server标签,只要在http标签的最后加上一个include

(conf文件是在conf/vhost/里面,但是这里不是写conf/vhost/*.conf,踩坑了。)

worker_processes  1;
error_log  logs/error.log  error;

events {
    worker_connections  1024;
}

http {


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

    log_format  main  ‘$remote_addr - $remote_user [$time_local] "$request" ‘
                      ‘$status $body_bytes_sent "$http_referer" ‘
                      ‘"$http_user_agent" "$http_x_forwarded_for"‘;

    #access_log  logs/access.log  main;

    sendfile        on;
    include vhost/*.conf;
}

  

conf/vhost/jab.com.conf 

server {
    listen       80;
    server_name  www.jab.com jab.com;
    root         /data/jab.com/;
    #charset koi8-r;

    access_log  logs/jab.com.log  main;

    location / {
        root /data/jab.com/;
        index index.php index.html;
    }

    location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}

  

nginx虚拟主机

原文:https://www.cnblogs.com/jabbok/p/9242761.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!