我是 Nginx 的新手,我正在尝试让子域正常工作。
我想做的是获取我的域(我们称之为example.com)并添加:
- sub1.example.com,
- sub2.example.com, 并且还有
- www.example.com可用的。
我知道如何用 Apache 做到这一点,但 Nginx 是一个真正令人头疼的问题。
我正在运行 Debian 6。
我当前的 /etc/nginx/sites-enabled/example.com:
server {
    server_name www.example.com example.com;
    access_log /srv/www/www.example.com/logs/access.log;
    error_log /srv/www/www.example.com/logs/error.log;
    root /srv/www/www.example.com/public_html;
    location / {
        index  index.html index.htm;
    }
    location ~ \.php$ {
        include /etc/nginx/fastcgi_params;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /srv/www/www.example.com/public_html$fastcgi_script_name;
    }
}
它正在努力为 example.com 和 www.example.com 提供服务。
我试图在同一个文件中添加第二个服务器块,例如:
server {
        server_name www.example.com example.com;
        access_log /srv/www/www.example.com/logs/access.log;
        error_log /srv/www/www.example.com/logs/error.log;
        root /srv/www/www.example.com/public_html;
        server {
            server_name sub1.example.com;
            access_log /srv/www/example.com/logs/sub1-access.log;
            error_log /srv/www/example.com/logs/sub1-error.log;
            root /srv/www/example.com/sub1;
    }
        location / {
            index  index.html index.htm;
        }
        location ~ \.php$ {
            include /etc/nginx/fastcgi_params;
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME /srv/www/www.example.com/public_html$fastcgi_script_name;
        }
}
没运气。有任何想法吗?我非常感谢任何反馈。