質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
nginx

nginixは軽量で高性能なwebサーバーの1つです。BSD-likeライセンスのもとリリースされており、あわせてHTTPサーバ、リバースプロキシ、メールプロキシの機能も備えています。MacOSX、Windows、Linux、上で動作します。

WordPress

WordPressは、PHPで開発されているオープンソースのブログソフトウェアです。データベース管理システムにはMySQLを用いています。フリーのブログソフトウェアの中では最も人気が高く、PHPとHTMLを使って簡単にテンプレートをカスタマイズすることができます。

PHP

PHPは、Webサイト構築に特化して開発されたプログラミング言語です。大きな特徴のひとつは、HTMLに直接プログラムを埋め込むことができるという点です。PHPを用いることで、HTMLを動的コンテンツとして出力できます。HTMLがそのままブラウザに表示されるのに対し、PHPプログラムはサーバ側で実行された結果がブラウザに表示されるため、PHPスクリプトは「サーバサイドスクリプト」と呼ばれています。

Debian

Debianは、Debian GNU/Linux などのOS(オペレーティングシステム)です。

Docker

Dockerは、Docker社が開発したオープンソースのコンテナー管理ソフトウェアの1つです

Q&A

解決済

1回答

972閲覧

Dockerを使用しDebian:buster, mariaDB, PHP,でwordpress環境を構築しようとしている502が改善できない。

tasads

総合スコア1

nginx

nginixは軽量で高性能なwebサーバーの1つです。BSD-likeライセンスのもとリリースされており、あわせてHTTPサーバ、リバースプロキシ、メールプロキシの機能も備えています。MacOSX、Windows、Linux、上で動作します。

WordPress

WordPressは、PHPで開発されているオープンソースのブログソフトウェアです。データベース管理システムにはMySQLを用いています。フリーのブログソフトウェアの中では最も人気が高く、PHPとHTMLを使って簡単にテンプレートをカスタマイズすることができます。

PHP

PHPは、Webサイト構築に特化して開発されたプログラミング言語です。大きな特徴のひとつは、HTMLに直接プログラムを埋め込むことができるという点です。PHPを用いることで、HTMLを動的コンテンツとして出力できます。HTMLがそのままブラウザに表示されるのに対し、PHPプログラムはサーバ側で実行された結果がブラウザに表示されるため、PHPスクリプトは「サーバサイドスクリプト」と呼ばれています。

Debian

Debianは、Debian GNU/Linux などのOS(オペレーティングシステム)です。

Docker

Dockerは、Docker社が開発したオープンソースのコンテナー管理ソフトウェアの1つです

0グッド

0クリップ

投稿2020/08/18 15:53

前提・実現したいこと

ここに質問の内容を詳しく書いてください。
Dockerを使用しDebian:buster, mariaDB, PHP,でwordpress環境を構築しようとしています。

発生している問題・エラーメッセージ

502エラーが発生してしまいます。
error.logは
下記のようなログを吐いています。

2020/08/18 11:28:59 [error] 315#315: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 172.17.0.1, server: _, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8000/", host: "localhost:8000"

該当のソースコード

Dockerfile

1FROM debian:buster 2 3RUN apt-get update &&\ 4 apt-get install -y\ 5 vim\ 6 openssl\ 7 nginx\ 8 less\ 9 wget\ 10 mariadb-server\ 11 php7.3-fpm php7.3-common php7.3-mysql\ 12 php7.3-gmp php7.3-curl php7.3-intl php7.3-mbstring\ 13 php7.3-xmlrpc php7.3-gd php7.3-xml\ 14 php7.3-cli php7.3-zip php7.3-soap php7.3-imap 15 16COPY ./srcs/run.sh ./run.sh 17COPY ./srcs/webserver ./etc/nginx/sites-available/webserver 18 19CMD bash ./run.sh

webserver

1## 2# You should look at the following URL's in order to grasp a solid understanding 3# of Nginx configuration files in order to fully unleash the power of Nginx. 4# https://www.nginx.com/resources/wiki/start/ 5# https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/ 6# https://wiki.debian.org/Nginx/DirectoryStructure 7# 8# In most cases, administrators will remove this file from sites-enabled/ and 9# leave it as reference inside of sites-available where it will continue to be 10# updated by the nginx packaging team. 11# 12# This file will automatically load configuration files provided by other 13# applications, such as Drupal or Wordpress. These applications will be made 14# available underneath a path with that package name, such as /drupal8. 15# 16# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples. 17## 18 19# Default server configuration 20# 21server { 22 listen 80 default_server; 23 listen [::]:80 default_server; 24 25 # SSL configuration 26 # 27 # listen 443 ssl default_server; 28 # listen [::]:443 ssl default_server; 29 # 30 # Note: You should disable gzip for SSL traffic. 31 # See: https://bugs.debian.org/773332 32 # 33 # Read up on ssl_ciphers to ensure a secure configuration. 34 # See: https://bugs.debian.org/765782 35 # 36 # Self signed certs generated by the ssl-cert package 37 # Don't use them in a production server! 38 # 39 # include snippets/snakeoil.conf; 40 41 root /var/www/html/wordpress; 42 43 # Add index.php to the list if you are using PHP 44 index index.html index.htm index.nginx-debian.html; 45 46 server_name _; 47 48 location / { 49 # First attempt to serve request as file, then 50 # as directory, then fall back to displaying a 404. 51 try_files $uri $uri/ =404; 52 proxy_pass http://127.0.0.1:8000; 53 allow all; 54 } 55 56 # pass PHP scripts to FastCGI server 57 58 #location ~ .php$ { 59 #include snippets/fastcgi-php.conf; 60 61 #With php-fpm (or other unix sockets): 62 #fastcgi_pass unix:/run/php/php7.3-fpm.sock; 63 #fastcgi_pass 127.0.0.1:9000; 64 #include /etc/nginx/conf.d/*.conf; 65 #include /etc/nginx/sites-enabled/*; 66 #fastcgi_intercept_errors on; 67 # With php-cgi (or other tcp sockets): 68 #fastcgi_pass 127.0.0.1:9000; 69 #} 70 71 # deny access to .htaccess files, if Apache's document root 72 # concurs with nginx's one 73 # 74 #location ~ /.ht { 75 # deny all; 76 #} 77} 78 79 80# Virtual Host configuration for example.com 81# 82# You can move that to a different file under sites-available/ and symlink that 83# to sites-enabled/ to enable it. 84# 85#server { 86# listen 80; 87# listen [::]:80; 88# 89# server_name example.com; 90# 91# root /var/www/example.com; 92# index index.html; 93# 94# location / { 95# try_files $uri $uri/ =404; 96# } 97#} 98

run

1#!/bin/sh 2 3service mysql start 4 5wget https://wordpress.org/latest.tar.gz -P ./tmp 6tar xzvf ./tmp/latest.tar.gz -C /var/www/html/ 7 8chown -R www-data:www-data /var/www/ 9chmod -R 755 /var/www/ 10echo "daemon off;" >> /etc/nginx/nginx.conf 11ln -s /etc/nginx/sites-available/webserver /etc/nginx/sites-enabled/ 12rm -rf /etc/nginx/sites-enabled/default 13 14 15service php7.3-fpm start 16service nginx start 17bash 18

試したこと

fpmの再起動等試してみましたが改善しませんでした。

記述で間違いがあるようでしたら指摘していただきたいです。
よろしくお願いします。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

mit0223

2020/08/19 10:02

php-fpm が起動していないのだと思いますが、php-fpm のログや /var/log/messages にエラーがでてませんか?
tasads

2020/08/19 14:38 編集

回答ありがとうございます。 fpmのログには [18-Aug-2020 11:28:59] NOTICE: fpm is running, pid 300 [18-Aug-2020 11:28:59] NOTICE: ready to handle connections [18-Aug-2020 11:28:59] NOTICE: systemd monitor interval set to 10000ms と出ていたので起動してると思ってるのですが。。。
TaichiYanagiya

2020/08/19 15:33

構成は、「*:80/nginx → fcgi(socket or port)/php-fpm」ではなく、「*:80/nginx → 127.0.0.1:8000/? → fcgi(socket or port)/php-fpm」なのですか? 8000 番ポートは何が担当しているのでしょうか?
tasads

2020/08/20 01:08

docker run --name *** -it -p 8000:80 *** でlocalの8000ポートとnginxの80ポートに接続しています。
guest

回答1

0

ベストアンサー

docker run の "-p 8000:80" は docker ホストの 8000 番ポートをコンテナの 80 番ポートへポートフォワードする設定です。
一方、nginx 設定 "proxy_pass http://127.0.0.1:8000;" はコンテナの 8000 番ポートへリバースプロキシーする設定なので、まったく関係がありません。

nginx から php-fpm に接続するための設定が必要です。
php-fpm は http ではなく fcgi で話しますので、proxy_pass ではなく、fastcgi_pass で接続します。

php-fpm 側で socket で待ち受けているのであれば、fastcgi_pass unix:(ソケットファイルのパス); とします。
nginx 実行ユーザーでソケットファイルにアクセスできるよう、php-fpm の設定ファイルでソケットファイルのオーナーやパーミッションを設定します。

php-fpm 側で TCP (9000 番ポートが使われることが多い) で待ち受けているのであれば、fastcgi_pass 127.0.0.1:9000; とします。

nginx 側では、fastcgi_pass の他に、fastcgi_param などの設定も必要になると思います。

投稿2020/08/20 01:29

TaichiYanagiya

総合スコア12146

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問