简体   繁体   English

错误 - nginx: [emerg] "server" 指令在 /etc/nginx/nginx.conf:1 中是不允许的

[英]Error - nginx: [emerg] "server" directive is not allowed here in /etc/nginx/nginx.conf:1

I created a docker-compose.yml file with Nginx, PHP-7.4-fpm, PhpMyAdmin and MariaDB, the execution of my docker-compose.yml has been deployed successfully but the Nginx container has an error:我使用 Nginx、PHP-7.4-fpm、PhpMyAdmin 和 MariaDB 创建了一个 docker-compose.yml 文件,我的 docker-compose.yml 的执行已成功部署,但 Nginx 容器出现错误:

nginx: [emerg] "server" directive is not allowed here in /etc/nginx/nginx.conf:1 nginx: [emerg] "server" 指令在 /etc/nginx/nginx.conf:1 中是不允许的

.docker/docker-compose.yml: .docker/docker-compose.yml:

version: '3'

services:
    nginx:
        image: nginx:alpine
        volumes:
            - ../:/code
            - ./config/nginx/nginx.conf:/etc/nginx/nginx.conf:ro
            - ./logs:/var/log/nginx
        ports:
            - "80:80"
        depends_on:
            - php

    php:
        build:
            context: './config/php/'
            args:
                PHP_VERSION: ${PHP_VERSION}
        depends_on:
            - mariadb
        volumes:
            - ../:/code
            - ./config/php/conf.d/xdebug.ini:/usr/local/etc/php/conf.d/xdebug.ini
        ports:
            - "9000:9000"

    mariadb:
        image: mariadb:${MARIADB_VERSION}
        restart: always
        ports:
            - "3306:3306"
        environment:
            - MYSQL_DATABASE=${MARIADB_DATABASE}
            - MYSQL_USER=${MARIADB_USER}
            - MYSQL_PASSWORD=${MARIADB_PASSWORD}
            - MYSQL_ROOT_PASSWORD=${MARIADB_ROOT_PASSWORD}
        volumes:
            - ./database:/var/lib/mysql

    phpmyadmin:
        image: phpmyadmin/phpmyadmin
        ports:
            - "${PHPMYADMIN_HTTP_PORT}:80"
        depends_on:
            - mariadb
        environment:
            - MYSQL_USER=${MARIADB_DATABASE}
            - MYSQL_PASSWORD=${MARIADB_PASSWORD}
            - MYSQL_ROOT_PASSWORD=${MARIADB_ROOT_PASSWORD}

.docker/config/nginx/nginx.conf: .docker/config/nginx/nginx.conf:

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;
    server_name monsite.local;
    root /code;

    index index.php index.html index.htm;

    location / {
        try_files $uri $uri/ /index.php;
    }

    location ~ \.php$ {
        try_files $uri /index.php =404;
        fastcgi_pass php:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    error_log /var/log/nginx/project_error.log;
    access_log /var/log/nginx/project_access.log;
}

I don't understand why I have this error, can you help me please ?我不明白为什么我有这个错误,你能帮我吗?

Thank you in advance先感谢您

In your context you need to wrap server in http block.在您的上下文中,您需要将服务器包装在 http 块中。 Or move you config file not by replacing the default config file, but rather replacing a default server config located in /etc/nginx/conf.d/ So you can use something like或者移动你的配置文件不是通过替换默认配置文件,而是替换位于 /etc/nginx/conf.d/ 中的默认服务器配置所以你可以使用类似的东西

        - ./nginx.conf:/etc/nginx/conf.d/default.conf

for volumes for nginx.用于 nginx 的卷。 That will rewrite your default server config.这将重写您的默认服务器配置。 You can also copy it to sites-enabled folder if you planning to use multiple config files.如果您打算使用多个配置文件,也可以将其复制到启用站点的文件夹。

Or you can modify your nginx config, by starting with wrapping it with http block或者你可以修改你的 nginx 配置,首先用 http 块包装它

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 nginx: [emerg] “server”指令在 /etc/nginx/conf.d 中是不允许的,即使服务器标签在 http 中 - nginx: [emerg] “server” directive is not allowed here in /etc/nginx/conf.d even if server tag is inside http nginx: [emerg] "http" 指令在 /etc/nginx/conf.d/default.conf:1 中是不允许的 - nginx: [emerg] "http" directive is not allowed here in /etc/nginx/conf.d/default.conf:1 nginx: [emerg] "http" 指令在 /etc/nginx/conf.d/site.conf:1 中是不允许的 - nginx: [emerg] "http" directive is not allowed here in /etc/nginx/conf.d/site.conf:1 docker 运行命令结束于:nginx:[emerg] 未知指令“events” in /etc/nginx/nginx.conf:1 - docker run command ends up in : nginx: [emerg] unknown directive “events” in /etc/nginx/nginx.conf:1 nginx:在 /etc/nginx/conf.d/nginx.conf:12 的上游“php”中找不到 [emerg] 主机 - nginx: [emerg] host not found in upstream "php" in /etc/nginx/conf.d/nginx.conf:12 nginx:在/etc/nginx/nginx.conf:44的上游“ tellform”中找不到[emerg]主机 - nginx: [emerg] host not found in upstream “tellform” in /etc/nginx/nginx.conf:44 emerg 1#1:在 /etc/nginx/nginx.conf:6 的上游“dashboard-fe:3000”中找不到主机 - emerg 1#1: host not found in upstream “dashboard-fe:3000” in /etc/nginx/nginx.conf:6 docker vs docker-compose nginx:[emerg] host在/etc/nginx/nginx.conf:21的上游“httpstat.us”中找不到 - docker vs docker-compose nginx: [emerg] host not found in upstream “httpstat.us” in /etc/nginx/nginx.conf:21 Docker 撰写错误:nginx:在 /etc/nginx/conf.d/default.conf:21 的上游“应用程序”中找不到 [emerg] 主机 - Docker compose error: nginx: [emerg] host not found in upstream “app” in /etc/nginx/conf.d/default.conf:21 nginx:[emerg] 在 /etc/nginx/conf.d/default.conf 的上游“api:5000”中找不到主机 - nginx: [emerg] host not found in upstream "api:5000" in /etc/nginx/conf.d/default.conf
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM