繁体   English   中英

Running wordpress on docker-compose,nginx, mysql and php

[英]Running wordpress on docker-compose,nginx, mysql and php

I need to run wordpress on docker-compose, nginx, php and mysql. 运行它后,我看到的只是“欢迎使用 nginx”,但看不到我的网站。

我不确定我是否必须在我的操作系统上配置一些东西(我在 Ubuntu 20.04 上)。

我看到 docker 容器,没有错误,但没有网站。 我不知道为什么。

这是我的配置:docker-compose.yml

version: "3"

services:
  nginx:
    image: nginx
    container_name: nginx
    ports:
      - 80:80
    volumes:
      - ./src:/src
      - ./site.conf:/etc/nginx/conf.d/site.conf
    links:
      - php
  db:
    image: mysql
    container_name: mysql
    ports:
      - 3306:3306
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: toor
    volumes:
      - db-data:/var/lib/mysql
  php:
    build:
      context: .
      dockerfile: ./php/Dockerfile
    image: php:7-fpm
    container_name: php
    volumes:
      - ./src:/src

volumes:
  db-data:

这是我的 dockerfile

# syntax=docker/dockerfile:1
FROM php:7-fpm
RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli

这是我的 site.conf

server {
    index index.php index.html;
    server_name engine.local;
    error_log  /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;
    root /src;
    location / {
        # This is cool because no php is touched for static content.
        # include the "?$args" part so non-default permalinks doesn't break when using query string
        try_files $uri $uri/ /index.php?$args;
    }
    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass php:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }

    #stolen from the nginx.conf
    # BEGIN W3TC Minify cache
    location ~ /wp-content/cache/minify/.*js_gzip$ {
        gzip off;
        types {}
        default_type application/x-javascript;
        add_header Content-Encoding gzip;
        expires 31536000s;
        etag on;
        if_modified_since exact;
        add_header Referrer-Policy "no-referrer-when-downgrade";
        add_header Vary "Accept-Encoding";
    }
    location ~ /wp-content/cache/minify/.*css_gzip$ {
        gzip off;
        types {}
        default_type text/css;
        add_header Content-Encoding gzip;
        expires 31536000s;
        etag on;
        if_modified_since exact;
        add_header Referrer-Policy "no-referrer-when-downgrade";
        add_header Vary "Accept-Encoding";
    }
    # END W3TC Minify cache
    # BEGIN W3TC Page Cache cache
    location ~ /wp-content/cache/page_enhanced.*gzip$ {
        gzip off;
        types {}
        default_type text/html;
        add_header Content-Encoding gzip;
        etag on;
        if_modified_since exact;
        add_header Referrer-Policy "no-referrer-when-downgrade";
    }
    # END W3TC Page Cache cache
    # BEGIN W3TC Browser Cache
    gzip on;
    gzip_types text/css text/x-component application/x-javascript application/javascript text/javascript text/x-js text/richtext text/plain text/xsd text/xsl text/xml image/bmp application/java application/msword application/vnd.ms-fontobject application/x-msdownload image/x-icon application/json application/vnd.ms-access video/webm application/vnd.ms-project application/x-font-otf application/vnd.ms-opentype application/vnd.oasis.opendocument.database application/vnd.oasis.opendocument.chart application/vnd.oasis.opendocument.formula application/vnd.oasis.opendocument.graphics application/vnd.oasis.opendocument.spreadsheet application/vnd.oasis.opendocument.text audio/ogg application/pdf application/vnd.ms-powerpoint image/svg+xml application/x-shockwave-flash image/tiff application/x-font-ttf audio/wav application/vnd.ms-write application/font-woff application/font-woff2 application/vnd.ms-excel;
    location ~ \.(css|htc|less|js|js2|js3|js4)$ {
        expires 31536000s;
        etag on;
        if_modified_since exact;
        try_files $uri $uri/ /index.php?$args;
    }
    location ~ \.(html|htm|rtf|rtx|txt|xsd|xsl|xml)$ {
        etag on;
        if_modified_since exact;
        try_files $uri $uri/ /index.php?$args;
    }
    location ~ \.(asf|asx|wax|wmv|wmx|avi|avif|avifs|bmp|class|divx|doc|docx|exe|gif|gz|gzip|ico|jpg|jpeg|jpe|webp|json|mdb|mid|midi|mov|qt|mp3|m4a|mp4|m4v|mpeg|mpg|mpe|webm|mpp|_otf|odb|odc|odf|odg|odp|ods|odt|ogg|ogv|pdf|png|pot|pps|ppt|pptx|ra|ram|svg|svgz|swf|tar|tif|tiff|_ttf|wav|wma|wri|xla|xls|xlsx|xlt|xlw|zip)$ {
        expires 31536000s;
        etag on;
        if_modified_since exact;
        try_files $uri $uri/ /index.php?$args;
    }
    add_header Referrer-Policy "no-referrer-when-downgrade";
    # END W3TC Browser Cache
    # BEGIN W3TC Minify core
    set $w3tc_enc "";
    if ($http_accept_encoding ~ gzip) {
        set $w3tc_enc _gzip;
    }
    if (-f $request_filename$w3tc_enc) {
        rewrite (.*) $1$w3tc_enc break;
    }
    rewrite ^/wp-content/cache/minify/ /index.php last;
    # END W3TC Minify core
    # BEGIN W3TC Page Cache core
    set $w3tc_rewrite 1;
    if ($request_method = POST) {
        set $w3tc_rewrite 0;
    }
    if ($query_string != "") {
        set $w3tc_rewrite 0;
    }
    if ($request_uri !~ \/$) {
        set $w3tc_rewrite 0;
    }
    if ($http_cookie ~* "(comment_author|wp\-postpass|w3tc_logged_out|wordpress_logged_in|wptouch_switch_toggle)") {
        set $w3tc_rewrite 0;
    }
    set $w3tc_preview "";
    if ($http_cookie ~* "(w3tc_preview)") {
        set $w3tc_preview _preview;
    }
    set $w3tc_ssl "";
    if ($scheme = https) {
        set $w3tc_ssl _ssl;
    }
    if ($http_x_forwarded_proto = 'https') {
        set $w3tc_ssl _ssl;
    }
    set $w3tc_enc "";
    if ($http_accept_encoding ~ gzip) {
        set $w3tc_enc _gzip;
    }
    if (!-f "$document_root/wp-content/cache/page_enhanced/$http_host/$request_uri/_index$w3tc_ssl$w3tc_preview.html$w3tc_enc") {
      set $w3tc_rewrite 0;
    }
    if ($w3tc_rewrite = 1) {
        rewrite .* "/wp-content/cache/page_enhanced/$http_host/$request_uri/_index$w3tc_ssl$w3tc_preview.html$w3tc_enc" last;
    }
    # END W3TC Page Cache core

    #end stolen
}

您没有指定尝试访问站点的方式,但您的错误清楚地表明您被路由到默认虚拟主机,而不是您配置的虚拟主机。

有2个解决方案:

  1. 您可以添加engine.local ,因为它在您的site.conf中配置到您的/etc/hosts ,例如:
     echo '127.0.0.1 engine.local' | sudo tee -a /etc/hosts
    在这种情况下,您将能够在浏览器中访问http://engine.local
  2. 您可以在site.conf engine.local更改为localhost 请记住重新启动您的 nginx 容器以使更改可见。 然后,您将能够从浏览器通过 http://localhost 访问该站点。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM