[英]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.