1

I know there are dupes of this out there, but I can't seem to solve this in my situation. I am installing and configuring nginx to have a useful and faster server for my VPS. I am using Putty command prompt. I am trying to create my own structure for this project. Why is nginx.conf syntax not okay? and why is this nginx.conf test unsuccessful is what I cannot understand. Could anyone provide some feedback?

And I get this error:

nginx: [emerg] "server" directive is not allowed here in /etc/nginx/sites-enabled/default:18
nginx: configuration file /etc/nginx/nginx.conf test failed

The configuration details are as follows:

# You may add here your
server {
        server_name 123.456.789.0;
        return 301 $scheme://example.com$request_uri;
# }
# statements for each of your virtual hosts to this file

### of Nginx configuration files in order to fully unleash the power of Nginx.
# http://wiki.nginx.org/Pitfalls
# http://wiki.nginx.org/QuickStart
# http://wiki.nginx.org/Configuration
#
# Generally, you will want to move this file somewhere, and start with a clean
# file but keep this around for reference. Or just disable in sites-enabled.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.##

server {
       listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;

        root /var/www/RESTfulAPI;
        index index.php index.html index.htm;

        # Make site accessible from http://localhost/
        server_name example.com;

        location / {
                  # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
                # Uncomment to enable naxsi on this location
                # include /etc/nginx/naxsi.rules
        }

        error_page 404 /404.html;
        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
  • 2
    Try removing # on line 5 and see what happens (assuming you are wanting the first server block in your configuration). – Paul Nov 14 '15 at 17:23
  • 1
    Also, this configuration is incomplete. There is no configuration or closing bracket for the last location block and no closing bracket for the server block it is in. – Paul Nov 14 '15 at 22:34
1

It appears you're missing some comments (#) on the first few lines.

Change:

# You may add here your
server {
        server_name 123.456.789.0;
        return 301 $scheme://example.com$request_uri;
# }
# statements for each of your virtual hosts to this file

to

# You may add here your
# server {
#        server_name 123.456.789.0;
#        return 301 $scheme://example.com$request_uri;
# }
# statements for each of your virtual hosts to this file
| improve this answer | |
1

Quoting from your error :

nginx: [emerg] "server" directive is not allowed here in /etc/nginx/sites-enabled/default:18

The issue seem to be situated at the first server directive on the top of your configuration file.

I find that there is one closing curly braces which you have commented:

# You may add here your
server {
        server_name 123.456.789.0;
        return 301 $scheme://example.com$request_uri;
# }
# statements for each of your virtual hosts to this file

You might want to comment the following block completely or remove the extra comment tag at the end of the server curly-braces.

| improve this answer | |

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.