nginx虚拟主机

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

人吐槽 人点赞

猜你喜欢

发表评论

用户名: 密码:
验证码: 匿名发表

你可以使用这些语言

查看评论:nginx虚拟主机