Docker nginx php 502

Docker w/ PHP-FPM & Nginx — 502 Bad Gateway

I’m currently trying to dockerise a Laravel application, I’ve managed to create my Dockerfile and docker-compose.yml with the dependencies I need. However, I am struggling to get php-fpm to kick in that will show my application. Dockerfile

# Set master image FROM php:8.0-fpm-alpine # Copy composer.lock and composer.json COPY composer.lock composer.json /var/www/html/ # Set working directory WORKDIR /var/www/html # Install Additional dependencies RUN apk update && apk add --no-cache \ build-base shadow vim curl \ php8 \ php8-fpm \ php8-common \ php8-pdo \ php8-pdo_mysql \ php8-mysqli \ php8-mbstring \ php8-xml \ php8-openssl \ php8-json \ php8-phar \ php8-zip \ php8-gd \ php8-dom \ php8-session \ php8-zlib \ nodejs \ npm # Add and Enable PHP-PDO Extenstions RUN docker-php-ext-install pdo pdo_mysql RUN docker-php-ext-enable pdo_mysql # Install PHP Composer RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer # Remove Cache RUN rm -rf /var/cache/apk/* # Add UID '1000' to www-data RUN usermod -u 1000 www-data # Copy existing application directory permissions COPY --chown=www-data:www-data . /var/www/html # Change current user to www USER www-data # Install app dependencies COPY package.json /var/www/html/ RUN npm install RUN npm run dev # Expose port 9000 and start php-fpm server EXPOSE 9000 CMD ["php-fpm"] 
version: '3' services: #Laravel App app: build: context: . dockerfile: Dockerfile image: heychazza/joinservers.com container_name: app restart: unless-stopped tty: true environment: SERVICE_NAME: app SERVICE_TAGS: dev working_dir: /var/www/html expose: - "9000:80" volumes: - ./:/var/www/html networks: - mynet #Nginx Service nginx: image: nginx:alpine container_name: nginx restart: unless-stopped tty: true ports: - "8080:80" volumes: - ./:/var/www/html - ./deployment/nginx/conf.d/:/etc/nginx/conf.d/ #- ./nginx/ssl/:/etc/nginx/ssl/ depends_on: - app networks: - mynet #MySQL Service db: image: mariadb:latest container_name: db restart: unless-stopped tty: true ports: - "33060:3306" environment: MYSQL_DATABASE: laraveldb MYSQL_USER: laravel MYSQL_PASSWORD: laravelpassworddb MYSQL_ROOT_PASSWORD: rootpasswordmysql MYSQL_ROOT_HOST: '%' volumes: - mysqldata:/var/lib/mysql/ networks: - mynet #Docker Networks networks: mynet: driver: bridge #Volumes volumes: mysqldata: driver: local 

What am I doing? I’m running Docker from a MacBook, and are looking to deploy this onto a production Debian machine. I’m still new to docker, so apologies if I’ve missed anything out.

Читайте также:  Селекторы выбора в html

Источник

Docker + nginx + Php-FPM 502 Bad Gateway

I’m trying to install php-fpm and nginx via docker and I have a problem with nginx which returns me a 502 Bad gateway error, however when I try to go on any HTML file only displays correctly. What must I do to a php file works correctly with this system? Nginx config site:

FROM ubuntu:13.10 # Keep upstart from complaining RUN dpkg-divert --local --rename --add /sbin/initctl RUN ln -sf /bin/true /sbin/initctl # Let the conatiner know that there is no tty ENV DEBIAN_FRONTEND noninteractive RUN locale-gen en_US.UTF-8 ENV LANG en_US.UTF-8 ENV LC_ALL en_US.UTF-8 RUN apt-get update && apt-get upgrade -y RUN apt-get -y install nginx php5-fpm php5-mysql php-apc pwgen python-setuptools curl git unzip RUN apt-get -y install php5-curl php5-gd php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-sqlite php5-tidy php5-xmlrpc VOLUME ["/var/log/nginx"] CMD echo "127.0.0.1 api.local.dev" >> /etc/hosts EXPOSE 80 RUN mkdir /www RUN chown www-data:www-data -R /www RUN echo "" > /www/index.php RUN cat /www/index.php RUN mkdir /docker ADD nginx /docker/nginx RUN mkdir -p /var/log/nginx RUN chown www-data:www-data /var/log/nginx RUN sed -i -e"s/keepalive_timeout\s*65/keepalive_timeout 2/" /etc/nginx/nginx.conf RUN sed -i -e"s/keepalive_timeout 2/keepalive_timeout 2;\n\tclient_max_body_size 100m/" /etc/nginx/nginx.conf RUN sed -i -e "s/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g" /etc/php5/fpm/php.ini RUN sed -i -e "s/upload_max_filesize\s*=\s*2M/upload_max_filesize = 100M/g" /etc/php5/fpm/php.ini RUN sed -i -e "s/post_max_size\s*=\s*8M/post_max_size = 100M/g" /etc/php5/fpm/php.ini RUN sed -i -e "s/;daemonize\s*=\s*yes/daemonize = no/g" /etc/php5/fpm/php-fpm.conf RUN sed -i -e "s/;catch_workers_output\s*=\s*yes/catch_workers_output = yes/g" /etc/php5/fpm/pool.d/www.conf RUN cat /etc/php5/fpm/pool.d/www.conf RUN find /etc/php5/cli/conf.d/ -name "*.ini" -exec sed -i -re 's/^(\s*)#(.*)/\1;\2/g' <> \; RUN echo "cgi.fix_pathinfo = 0;" >> /etc/php5/fpm/php.ini RUN cat /docker/nginx/api.local.dev > /etc/nginx/sites-available/api.local.dev RUN ln -s /etc/nginx/sites-available/api/local.dev /etc/nginx/sites-enabled/api/local.dev RUN echo "daemon off;" >> /etc/nginx/nginx.conf CMD ["nginx"] 
user www-data; worker_processes 4; pid /run/nginx.pid; events < worker_connections 768; # multi_accept on; >http < ## # Basic Settings ## sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; # server_tokens off; # server_names_hash_bucket_size 64; # server_name_in_redirect off; include /etc/nginx/mime.types; default_type application/octet-stream; ## # Logging Settings ## access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; ## # Gzip Settings ## fastcgi_buffers 8 16k; fastcgi_buffer_size 32k; gzip on; gzip_disable "msie6"; # gzip_vary on; # gzip_proxied any; # gzip_comp_level 6; # gzip_buffers 16 8k; # gzip_http_version 1.1; # gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript; ## # nginx-naxsi config ## # Uncomment it if you installed nginx-naxsi ## #include /etc/nginx/naxsi_core.rules; ## # nginx-passenger config ## # Uncomment it if you installed nginx-passenger ## #passenger_root /usr; #passenger_ruby /usr/bin/ruby; ## # Virtual Host Configs ## include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; >#mail < # # See sample authentication script at: # # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript # # # auth_http localhost/auth.php; # # pop3_capabilities "TOP" "USER"; # # imap_capabilities "IMAP4rev1" "UIDPLUS"; # # server < # listen localhost:110; # protocol pop3; # proxy on; # ># # server < # listen localhost:143; # protocol imap; # proxy on; # >#> 

Источник

Читайте также:  Cmd java jar file

Nginx 502 Bad Gateway Docker error | Troubleshooting Tips

At Bobcares, we offer solutions for every query, big and small, as a part of our Docker Hosting Support Service.

Let’s take a look at how our Support Team is ready to help customers resolve Nginx 502 bad gateway Docker error.

How to resolve Nginx 502 bad gateway docker

Some of our customers have been coming across the 502 Bad Gateway error message when they attempt to have a docker container with Nginx work as a reverse proxy. Fortunately, our Support Team has come up with several different ways to resolve this specific issue.

Nginx 502 Bad Gateway Docker

Troubleshooting Tips: Nginx 502 Bad Gateway

Option 1:

  1. First, we have to set the server name. This is done in different server blocks in the Nginx configuration. Our Support Techs would like to point out that we have to use the docker port rather than the host port in this scenario.

Option 2:

If the above solution did not resolve the issue, our Support Techs recommend tuning proxy_buffer_size as seen below:

proxy_buffering off; proxy_buffer_size 16k; proxy_busy_buffers_size 24k; proxy_buffers 64 4k;

proxy_buffer_size defines how much memory Nginx will allocate for each request. This memory is put to use for reading as well as storing the HTTP headers of the response.

Option 3:

This solution involves declaring the external network in case the container we are pointing to is defined in a different docker-compose.yml file:

version: "3" services: webserver: image: nginx:1.17.4-alpine container_name: $-webserver depends_on: - drupal restart: unless-stopped ports: - 80:80 volumes: - ./docroot:/var/www/html - ./nginx-conf:/etc/nginx/conf.d - certbot-etc:/etc/letsencrypt networks: - internal - my-passwords networks: my-passwords: external: true name: my-passwords_default nginx.conf: server < listen 80; server_name test2.com www.test2.com; location / < proxy_pass http://my-passwords:3000/; >>

Option 4:

In this solution, the localhost points to the container itself. In other words, with an upstream like the one below:

docker run --name nginx -d -v /root/nginx/conf:/etc/nginx/conf.d --net=host nginx

Last but not least, another approach to resolve the issue is to reconfigure the Nginx upstream directive in order to directly connect to the host machine via adding a remote IP address:

Let us know in the comments which troubleshooting tip works for you. If you are still having trouble, drop us a line and our Support Techs will help you out in a jiffy.

Conclusion

To sum up, our skilled Support Engineers at Bobcares demonstrated how to resolve Nginx 502 bad gateway docker.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you. Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure. GET STARTED

Источник

Почему не удаётся запустить docker связку nginx+php-fpm?

Только изучаю вопрос — пока нет целей примонтировать каталог. Пытаюсь избавиться от ошибки 502 (при localhost:8080).

601b7f5186432178473687.jpeg

1.1. Имею конфиг-файл для nginx (localhost:8080)

2. И докер файлы
2.1 Docker file для nginx ( \site\docker\nginx\Dockerfile)

FROM nginx:1.17-alpine #COPY ./docker/nginx/conf.d /etc/nginx/conf.d COPY ./././docker/nginx/conf.d ./etc/nginx/conf.d #COPY ./public ./public COPY ./public ./app/public WORKDIR /app

2.2. докер фал для php-fpm (\site\docker\php-fpm\Dockerfile)

3. Провожу сборку (всё ок, ошибок нет)

docker build --file=site/docker/nginx/Dockerfile --tag=site-nginx site docker build --file=site/docker/php-fpm/Dockerfile --tag=site-php-fpm site docker network create site docker run -d --network site --name php-fpm site-php-fpm docker run -d --network site --name nginx -p 8080:80 site-nginx

4. проверяю пути в контейнерах
nginx:
/etc/nginx/conf.d/default.conf — скопирован
/app/public/index.php — скопирован
php-fpm:
/app/public/index.php — скопирован

5. Результат
502 Bad Gateway
nginx/1.17.10

6. Логи
при этом логи
nginx:
/var/log/nginx/access.log — пуст
/var/log/nginx/error.log — пуст

php-fpm:
отдельного лога нет
логи апатча — пусты

Простой 4 комментария

Источник

Оцените статью