代码之家  ›  专栏  ›  技术社区  ›  Даниил Чернюк

在Nginx-config的Laravel+Nginx+MariaDB docker容器中出现问题

  •  0
  • Даниил Чернюк  · 技术社区  · 3 年前

    我有一个由nginx、php和MariaDB容器组成的docker,但当我放入nginx.conf http{}块时,他很难过,这是不正确的,但它来自互联网示例。

    docker-compose file
    version: '3'
    
    services:
      nginx:
        image: nginx:latest
        volumes:
          - ./:/var/www
          - ./_docker/nginx/conf.d:/etc/nginx/conf.d
        ports:
          - "8081:80"
        depends_on:
          - app
        container_name: beach_nginx
      
      app:
        build:
          args:
            user: dancher
            uid: 1000
            gid: 1000
          context: .
          dockerfile: _docker/app/Dockerfile
        volumes:
          - ./:/var/www
        ports:
          - '8082:80'
        depends_on:
          - db
        container_name: beach_appx
    
      
      db:
        image: mariadb:10.10
        
        restart: always
        volumes:
          - ./tmp/db:/var/lib/mysql
        environment:
          MARIADB_DATABASE: beach_db
          MARIADB_ROOT_PASSWORD: root
        
        ports:
          - 8101:3306
        command: mysqld --character-set-server=utf8 --collation-server=utf8_unicode_ci
    

    它是nginx.conf文件中的config。Http不能放在这行,他很伤心。用户nginx也不能放在这里。如果我删除所有并保存服务器{location/},我的配置就会起作用。

    user  nginx;
    worker_processes auto;
    worker_cpu_affinity auto;
    worker_rlimit_nofile 30000;
    pid /var/run/nginx.pid;
    pcre_jit on;
    
    events {
        worker_connections 8192;
        multi_accept on;
    }
    
    http {
    
        # Basic #######################
        
        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        reset_timedout_connection on;
        keepalive_timeout 120;
        keepalive_requests      1000;
        types_hash_max_size     2048;
        server_tokens       off;
        send_timeout        30;
        client_body_timeout     30;
        client_header_timeout   30;
        server_names_hash_max_size  4096;
    
        # Limits ######################
        
        client_max_body_size    10m;
        client_body_buffer_size 128k;
        client_body_temp_path   /var/cache/nginx/client_temp;
    
        proxy_connect_timeout   60;
        proxy_send_timeout      60;
        proxy_read_timeout      60;
        proxy_buffer_size       4k;
        proxy_buffers       8 16k;
        proxy_busy_buffers_size 64k;
        proxy_temp_file_write_size  64k;
        proxy_temp_path     /var/cache/nginx/proxy_temp;
    
        include       /etc/nginx/mime.types;
        default_type  application/octet-stream;
     
        # Logs ########################
    
        m_header_time';
    
        access_log  /var/log/nginx/access.log  main;
        error_log  /var/log/nginx/error.log;
    
        # Gzip ########################
    
        gzip on; 
        gzip_static on; 
        gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript image/x-icon image/svg+xml application/x-font-ttf;
        gzip_comp_level 9;
        gzip_proxied any;
        gzip_min_length 1000;
        gzip_disable "msie6";
        gzip_vary on;
    
        etag off;
        
        include /etc/nginx/conf.d/*.conf;
    
        # For monitoring ###########
        
        server {
    
        index index.html index.php;
        error_log  /var/log/nginx/error.log;
        access_log /var/log/nginx/access.log;
        root /var/www/public;
        client_max_body_size 50m;
        
        location / {
            #Basic
    
            sendfile on;
            tcp_nopush on;
            tcp_nodelay on;
            reset_timedout_connection on;
            #keepalive_timeout 120;
            keepalive_requests 1000;
            types_hash_max_size 2048;
            server_tokens off;
            send_timeout 30;
            client_body_timeout 30;
            #client_header_timeout 30;
            #server_names_hash_max_size 4096;
            try_files $uri $uri/ /index.php?$query_string;
            proxy_connect_timeout 60s;
            limit_req zone=one;
            # kill cache
            add_header Last-Modified $date_gmt;
            add_header Cache-Control 'no-store, no-cache';
            if_modified_since off;
            expires off;
            etag off;
        }
    
        location ~ \.php$ {
            try_files $uri =404;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass app:9000;
            fastcgi_index index.php;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param PATH_INFO $fastcgi_path_info;
        }
    
    }
    }`
    

    我试着把http{}块放在不同的地方,但它不起作用。

    0 回复  |  直到 3 年前