【问题标题】:Why doesn't my image work on the Jelastic server?为什么我的图像在 Jelastic 服务器上不起作用?
【发布时间】:2020-11-26 19:44:36
【问题描述】:

我从 jelastic/nginxphp:1.18.0-php-7.4.10 镜像创建了一个 docker 镜像来运行我的 Laravel 项目。

图像在本地正常工作。但是当我尝试从 Jeslatic 服务器加载图像时,在浏览器中打开时出现 502 错误。

我该如何解决这个问题? (不产生日志)

Dockerfile

FROM jelastic/nginxphp:1.18.0-php-7.4.10

WORKDIR /var/www/webroot

COPY server-conf/nginx/conf.d/nginx.conf /etc/nginx/nginx.conf

COPY . .

RUN chmod -R 777 storage

RUN COMPOSER_MEMORY_LIMIT=-1 composer install --optimize-autoloader --no-interaction --no-progress --no-dev

CMD service php-fpm start && nginx -g "daemon off;"

nginx.conf

#user  nobody;
worker_processes  auto;
worker_rlimit_nofile 2048;

#load_module modules/ngx_http_modsecurity_module.so;

error_log  /var/log/nginx/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  2048;
}


http {
    server_tokens off;
    include       mime.types;
    default_type  application/octet-stream;
    client_max_body_size 100m;

    log_format  main  '$remote_addr:$http_x_remote_port - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for" '
                      '"$host" sn="$server_name" '
                      'rt=$request_time '
                      'ua="$upstream_addr" us="$upstream_status" '
                      'ut="$upstream_response_time" ul="$upstream_response_length" '
                      'cs=$upstream_cache_status' ;

    access_log  /var/log/nginx/access.log main;
    sendfile        on;
    keepalive_timeout  65;

    gzip  on;
    gzip_types text/plain text/xml text/css application/xml application/xhtml+xml application/rss+xml application/javascript application/x-javascript;

    server {
        listen       80 ;
        listen       [::]:80;
        server_name  _;

        charset utf-8;

        access_log  /var/log/nginx/host.access.log;
        error_log  /var/log/nginx/host.error.log;
        include /etc/nginx/aliases.conf;

        index index.php;
        root   /var/www/webroot/public;

        add_header X-Frame-Options "SAMEORIGIN";
        add_header X-XSS-Protection "1; mode=block";
        add_header X-Content-Type-Options "nosniff";


        #modsecurity on;
        #modsecurity_rules_file /etc/nginx/conf.d/modsecurity/modsec_includes.conf;

        if ($http_x_remote_port = '' ) {
           set $http_x_remote_port $remote_port;
        }

        # enforce NO www
        if ($host ~* ^www\.(.*)) {
            set $host_without_www $1;
            rewrite ^/(.*)$ $scheme://$host_without_www/$1 permanent;
        }
        # unless the request is for a valid file (image, js, css, etc.), send to bootstrap
        if (!-e $request_filename)
        {
            rewrite ^/(.*)$ /index.php?/$1 last;
            break;
        }

        error_page 404 /index.php;

        location = /favicon.ico { access_log off; log_not_found off; }
        location = /robots.txt  { access_log off; log_not_found off; }
        #location /ws {
        #    proxy_pass http://websocket;
        #    proxy_http_version 1.1;
        #    proxy_set_header Upgrade $http_upgrade;
        #    proxy_set_header Connection "Upgrade";
        #}


        # serve static files directly
        location ~* \.(jpg|jpeg|gif|css|png|js|ico|html)$ {
            access_log off;
            expires max;
            log_not_found off;
        }

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

        location ~ \.php$ {
            #location ~ /\. { deny all; access_log off; log_not_found off; }
            include /etc/nginx/fastcgi_params;
            fastcgi_pass unix:/var/run/php-fpm.socket;
            fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
            fastcgi_param DOCUMENT_ROOT $realpath_root;
            fastcgi_param PATH_INFO $fastcgi_script_name;
        }

        location ~ /\.(?!well-known).* {
                deny all;
        }
    }

    include /etc/nginx/conf.d/*.conf;

}

我的拓扑

【问题讨论】:

    标签: laravel docker nginx dockerfile jelastic


    【解决方案1】:

    如果您遇到同样的问题,我会为您提供解决方案。

    这是我的 dockerfile

    FROM jelastic/nginxphp:1.18.0-php-7.4.10
    
    # Active extension
    RUN sed -i "s|;zend_extension=/usr/lib64/php/modules/xdebug.so|zend_extension=/usr/lib64/php/modules/xdebug.so|g" /etc/php.ini
    
    
    # Get latest Composer
    COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
    
    WORKDIR /var/www/
    
    COPY /nginx/nginx.conf /etc/nginx/nginx.conf
    
    COPY . .
    
    RUN composer install --prefer-dist --no-ansi --no-interaction --no-progress --no-scripts
    
    COPY .env.example .env
    
    # Give storage folder write permission by the webserver
    RUN chmod -R 777 storage bootstrap
    
    # Clear cache
    RUN php artisan cache:clear; rm -rf bootstrap/cache/*
    
    RUN php artisan key:generate
    
    EXPOSE 9000
    
    CMD service php-fpm start && nginx -g "daemon off;"
    

    如果您有任何改进建议,请随时发表评论

    【讨论】:

      猜你喜欢
      • 2014-01-26
      • 2013-09-20
      • 1970-01-01
      • 1970-01-01
      • 2013-03-28
      • 1970-01-01
      • 2012-01-12
      • 2020-03-23
      • 2019-05-22
      相关资源
      最近更新 更多