Nginx [emerg] “server” directive is not allowed here


Nginx [emerg] “server” directive is not allowed here



I'm coming with problem with NGinx - probably it's my fault somewhere but I can't find solution.



I made custom vhost block in DEFAULT nginx config. And I don't know if it's problem of that and I should do custom vhost in other file in "sites-available" or it's possible in this nginx config.



I'm struggling with that error:



[root@openvpn etc]# nginx -t



nginx: [emerg] "server" directive is not allowed here in /etc/nginx/nginx.conf:69



nginx: configuration file /etc/nginx/nginx.conf test failed



Here it's my nginx.conf


nginx.conf


# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
worker_connections 1024;
}

http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log /var/log/nginx/access.log main;

sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;

include /etc/nginx/mime.types;
default_type application/octet-stream;

# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;


index index.php index.html;

# Default server block
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name 1.2.3.4;
root /usr/share/nginx/html;

# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;

location / {
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}

location ~ .php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

# Wordpress server
server {
server_name www.tested-dev.tk tested-dev.tk;
access_log logs/tested-dev.access.log main;

root /var/www/tested-dev.tk/;

location / {
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ .php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
}
}



Someone maybe have idea how to resolve that problem with second block (without giving it to second conf file)? And how I can optimize blocks?



Oh I should say why I won't "second block conf file".
Because on centos and in internet I can't find default site block file to copy to sites-available because every time when I'm starting configurating with


sites-available


server {
...
}



I'm getting same thing about "server" directive is not allowed here.




1 Answer
1



The "wordpress" server block is nested within the default server block, but it should be at the same level.



This is what you have:


server {
...
server {
# Your WordPress config
...
}
}



Should be this way instead:


server {
...
}

server {
# Your WordPress config
...
}





Oh... how I could miss that - thanks.
– TheTanadu
Jul 2 at 10:00





Could you lookup at #Edit?
– TheTanadu
Jul 2 at 10:52






That should a separate question as it is quite unrelated to the original problem
– kristaps
Jul 2 at 11:21





Oh, ok - I will do it
– TheTanadu
Jul 2 at 11:36






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Rothschild family

Cinema of Italy