Linux 下Nginx配置多站点

2016-09-13 05:21:29   服务器

  nginx  

当前环境

nginx : 1.9.5 centos : 7.0 nginx 安装目录 : /usr/local/nginx

创建存放多站点配置文件目录

cd /usr/local/nginx
mkdir vhost

修改nginx.conf

http {
    ......
    include vhost/*.conf;
}

创建站点配置

cd vhost
touch www.moell.cn.conf
vi www.moell.cn.conf

server {
        listen       80;
        #域名
        server_name   www.moell.cn;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        root /www/moell;    #应用目录
        location / {
            root   /www/moell;  #应用没录
            index  index.php index.html index.htm;
        }

        #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   html;
        }

        # 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$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            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;
        #}
    }