Nginx conf failed cause of server directive not allowed

nginx

I have a problem with one of my vhost. When I restart nginx, it's fail.

So I tried :

nginx -c /etc/nginx/sites-available/website -t

And here is my problem :

nginx: [emerg] "server" directive is not allowed here in
/etc/nginx/sites-available/website:1

I looked at this post : nginx server directive is not allowed here but my nginx.conf is correct, I don't have his problem.

Here is the content of website config :

server {
        server_name www.weacms.com;
        root /home/ebuildy/website/weacms;
        index index.html index.php;

        pagespeed on;
        pagespeed FileCachePath /var/ngx_pagespeed_cache;

        location / {
                try_files $uri $uri/ /index.php;
                location = /index.php {
                        fastcgi_pass unix:/var/run/php5-fpm.sock;
                        fastcgi_param SCRIPT_FILENAME $request_filename;
                        include fastcgi_params;
                }
        }

        location ~* \.(css|js|gif|jpe?g|png)$ {
                expires 168h;
                log_not_found off;
                add_header Pragma public;
                add_header Cache-Control "public, must-revalidate, proxy-revali$
        }
}

My config is included in nginx.conf :

        ...
        # Virtual Host Configs    
        #include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;
}

Does someone see where is the problem ? thanks.

Best Answer

You don't test your complete configuration, just the subsite defined in the file /etc/nginx/sites-available/website. This is not a valid nginx configuration file on it's own.

Try it with nginx -c /etc/nginx/nginx.conf -t or wherever your main config file is located.