代码之家  ›  专栏  ›  技术社区  ›  TheTanadu

这里不允许nginx[emerg]“server”指令

  •  0
  • TheTanadu  · 技术社区  · 7 年前

    我和nginx有问题-可能是我的错,但我找不到解决办法。

    我在默认nginx配置中创建了自定义vhost块。我不知道这是不是问题所在,我应该在“可用站点”的其他文件中定制vhost,或者在nginx配置中也可以这样做。

    我正在努力解决这个错误:

    [根@openvpn等]nginx-t

    nginx:[emerg]/etc/nginx/nginx.conf:69中不允许使用“server”指令

    nginx:配置文件/etc/nginx/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;
                    }
            }
        }
    }
    

    有人可能知道如何用第二个块解决这个问题(而不把它交给第二个conf文件)?如何优化块?

    哦,我应该说为什么我不“第二块conf文件”。 因为在CentOS和Internet上找不到要复制到的默认网站阻止文件 sites-available 因为每次我开始配置

     server {
     ...
     }
    

    我对“server”指令也有同样的看法,这里不允许使用。

    1 回复  |  直到 7 年前
        1
  •  2
  •   kristaps    7 年前

    “wordpress”服务器块嵌套在默认的服务器块中,但它应该处于同一级别。

    这就是你所拥有的:

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

    应该是这样的:

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