【发布时间】: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