ubuntu nginx 創建多個站點

1、打開 etc下hosts 文件

/etc/hosts

添加 127.0.0.1 mysite

2、打開etc下nginx

/etc/nginx

創建vhosts文件夾,將sites-enabled目錄下的default文件拷貝到vhosts目錄下。

並將server_name localhost 修改成第一步中的mysite。


server {

    listen   80;
    server_name mysite;                    //第一個站點爲localhost,第二個站點爲mysite

    index index.php index.html index.htm;
    set $root_path '/home/mysite/public';
    root $root_path;

    try_files $uri $uri/ @rewrite;

    location @rewrite {
        rewrite ^/(.*)$ /index.php?_url=/$1;
    }

    location ~ \.php {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index /index.php;

        include /etc/nginx/fastcgi_params;

        fastcgi_split_path_info       ^(.+\.php)(/.+)$;
        fastcgi_param PATH_INFO       $fastcgi_path_info;
        fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

    location ~* ^/(css|img|js|flv|swf|download)/(.+)$ {
        root $root_path;
    }


3、最後 重啓nginx, sudo /etc/init.d/nginx restart

訪問站點時需要在域名前加上http://,如:http://mysite,否則部分瀏覽器可能會出現無法正常打開的情況。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章