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.

  • please show /etc/nginx/nginx.conf have you included website.conf to nginx.conf – user255265 Nov 26 '14 at 7:30
  • Question updated, my nginx.conf is the basic one, all conf are included. I have only website.conf, and the default.conf. – Vincent LITUR Nov 26 '14 at 7:43

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.

  • Damn ! Thanks for this explanation ! I had an other error located in the default conf. Thanks a lot ! You saved my day. – Vincent LITUR Nov 26 '14 at 8:33
  • 1
    may service nginx configtest without path to config. – user255265 Nov 26 '14 at 9:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.