evertramos / docker-wordpress

Wordpress Docker container using SSL Certificates with LetsEncrypt
https://evertramos.github.io/docker-wordpress/
MIT License
486 stars 155 forks source link

Use wordpress-fpm #15

Closed KZARCA closed 4 years ago

KZARCA commented 6 years ago

Hi, thank you for your work ! I noticed that you used the image wordpress:latest which contains apache server. Is it possible to use another wordpress image, such as php7.0-fpm, to use it directly with nginx?

Best !

evertramos commented 6 years ago

I think it´s possible. Please give it a try and let us know. I will be off line for a couple weeks now, but we probably will have to adjust something in the proxy if it does not work.

KZARCA commented 6 years ago

Hi! I tried to add VIRTUAL_PROTO: fastcgi and VIRTUAL_ROOT: /var/www/html in the docker-compose file, but it does not seem to be enough. I tried a minimal example (without letsencrypt) to test it:

First, I started nginx-proxy:

version: '3.1'
services:
  nginx-proxy:
    image: jwilder/nginx-proxy
    ports:
      - "80:80"
    volumes:
     - /var/run/docker.sock:/tmp/docker.sock:ro
networks:
  default:
    external:
      name: test-proxy

And then wordpress + mysql

  wordpress:
    image: wordpress:php7.0-fpm
    restart: always
    environment:
      WORDPRESS_DB_PASSWORD: example
      VIRTUAL_PROTO: fastcgi
      VIRTUAL_ROOT: /var/www/html
      VIRTUAL_HOST: test-virtu
  mysql:
    image: mysql:5.7
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: example
networks:
  default:
    external:
      name: test-proxy
evertramos commented 6 years ago

What was the result? What the log says? You could use this version of proxy (docker-compose-letsencrypt-nginx-proxy-companion), which should be running before the wordpress and then start this environment.

Please post logs of proxy and wordpress to see whats going on.

PROTO might not be what you want. Please read jwilder helper carefully.

KZARCA commented 6 years ago

When I start nginx-proxy image, I get:

Creating dockerpvalue_nginx-proxy_1 ... done
Attaching to dockerpvalue_nginx-proxy_1
nginx-proxy_1  | WARNING: /etc/nginx/dhparam/dhparam.pem was not found. A pre-generated dhparam.pem will be used for now while a new one
nginx-proxy_1  | is being generated in the background.  Once the new dhparam.pem is in place, nginx will be reloaded.
nginx-proxy_1  | forego     | starting dockergen.1 on port 5000
nginx-proxy_1  | forego     | starting nginx.1 on port 5100
nginx-proxy_1  | dockergen.1 | 2018/05/23 14:15:47 Contents of /etc/nginx/conf.d/default.conf did not change. Skippingnotification 'nginx -s reload'
nginx-proxy_1  | dockergen.1 | 2018/05/23 14:15:47 Watching docker events
nginx-proxy_1  | dockergen.1 | 2018/05/23 14:15:47 Contents of /etc/nginx/conf.d/default.conf did not change. Skippingnotification 'nginx -s reload'
nginx-proxy_1  | 2018/05/23 14:16:00 [notice] 53#53: signal process started
nginx-proxy_1  | Generating DH parameters, 2048 bit long safe prime, generator 2
nginx-proxy_1  | This is going to take a long time
nginx-proxy_1  | dhparam generation complete, reloading nginx

then I start mysql+wordpress

mysql_1      | 2018-05-23T14:16:37.152484Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
mysql_1      | 2018-05-23T14:16:37.153464Z 0 [Note] mysqld (mysqld 5.7.21) starting as process 1 ...
mysql_1      | 2018-05-23T14:16:37.169287Z 0 [Note] InnoDB: PUNCH HOLE support available
mysql_1      | 2018-05-23T14:16:37.169304Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
mysql_1      | 2018-05-23T14:16:37.169308Z 0 [Note] InnoDB: Uses event mutexes
mysql_1      | 2018-05-23T14:16:37.169311Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
mysql_1      | 2018-05-23T14:16:37.169313Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.3
mysql_1      | 2018-05-23T14:16:37.169316Z 0 [Note] InnoDB: Using Linux native AIO
mysql_1      | 2018-05-23T14:16:37.169513Z 0 [Note] InnoDB: Number of pools: 1
mysql_1      | 2018-05-23T14:16:37.169627Z 0 [Note] InnoDB: Using CPU crc32 instructions
mysql_1      | 2018-05-23T14:16:37.170774Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
mysql_1      | 2018-05-23T14:16:37.177564Z 0 [Note] InnoDB: Completed initialization of buffer pool
mysql_1      | 2018-05-23T14:16:37.178988Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
mysql_1      | 2018-05-23T14:16:37.198009Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
mysql_1      | 2018-05-23T14:16:37.218790Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
mysql_1      | 2018-05-23T14:16:37.218873Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
mysql_1      | 2018-05-23T14:16:37.273694Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
mysql_1      | 2018-05-23T14:16:37.274349Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
mysql_1      | 2018-05-23T14:16:37.274357Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
mysql_1      | 2018-05-23T14:16:37.274545Z 0 [Note] InnoDB: Waiting for purge to start
mysql_1      | 2018-05-23T14:16:37.324685Z 0 [Note] InnoDB: 5.7.21 started; log sequence number 12319155
mysql_1      | 2018-05-23T14:16:37.325441Z 0 [Note] Plugin 'FEDERATED' is disabled.
mysql_1      | 2018-05-23T14:16:37.325455Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
mysql_1      | 2018-05-23T14:16:37.332733Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them.
mysql_1      | 2018-05-23T14:16:37.335177Z 0 [Warning] CA certificate ca.pem is self signed.
mysql_1      | 2018-05-23T14:16:37.336604Z 0 [Note] InnoDB: Buffer pool(s) load completed at 180523 14:16:37
mysql_1      | 2018-05-23T14:16:37.337991Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
mysql_1      | 2018-05-23T14:16:37.338029Z 0 [Note] IPv6 is available.
mysql_1      | 2018-05-23T14:16:37.338034Z 0 [Note]   - '::' resolves to '::';
mysql_1      | 2018-05-23T14:16:37.338044Z 0 [Note] Server socket created on IP: '::'.
mysql_1      | 2018-05-23T14:16:37.342317Z 0 [Warning] 'user' entry 'root@localhost' ignored in --skip-name-resolve mode.
mysql_1      | 2018-05-23T14:16:37.342460Z 0 [Warning] 'user' entry 'mysql.session@localhost' ignored in --skip-name-resolve mode.
mysql_1      | 2018-05-23T14:16:37.342471Z 0 [Warning] 'user' entry 'mysql.sys@localhost' ignored in --skip-name-resolve mode.
mysql_1      | 2018-05-23T14:16:37.342617Z 0 [Warning] 'db' entry 'performance_schema mysql.session@localhost' ignored in --skip-name-resolve mode.
mysql_1      | 2018-05-23T14:16:37.342623Z 0 [Warning] 'db' entry 'sys mysql.sys@localhost' ignored in --skip-name-resolve mode.
mysql_1      | 2018-05-23T14:16:37.342781Z 0 [Warning] 'proxies_priv' entry '@ root@localhost' ignored in --skip-name-resolve mode.
mysql_1      | 2018-05-23T14:16:37.347098Z 0 [Warning] 'tables_priv' entry 'user mysql.session@localhost' ignored in --skip-name-resolve mode.
mysql_1      | 2018-05-23T14:16:37.347111Z 0 [Warning] 'tables_priv' entry 'sys_config mysql.sys@localhost' ignored in --skip-name-resolve mode.
mysql_1      | 2018-05-23T14:16:37.355621Z 0 [Note] Event Scheduler: Loaded 0 events
mysql_1      | 2018-05-23T14:16:37.355729Z 0 [Note] mysqld: ready for connections.
mysql_1      | Version: '5.7.21'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server (GPL)
wordpress_1  | [23-May-2018 14:16:37] NOTICE: fpm is running, pid 1
wordpress_1  | [23-May-2018 14:16:37] NOTICE: ready to handle connections

Then I get from nginx-proxy:

nginx-proxy_1  | dockergen.1 | 2018/05/23 14:16:36 Received event start for container 8a88c5ebc9c8
nginx-proxy_1  | dockergen.1 | 2018/05/23 14:16:36 Contents of /etc/nginx/conf.d/default.conf did not change. Skippingnotification 'nginx -s reload'
nginx-proxy_1  | dockergen.1 | 2018/05/23 14:16:37 Received event start for container 47c6ef96a83b
nginx-proxy_1  | dockergen.1 | 2018/05/23 14:16:37 Generated '/etc/nginx/conf.d/default.conf' from 3 containers
nginx-proxy_1  | dockergen.1 | 2018/05/23 14:16:37 Running 'nginx -s reload'
nginx-proxy_1  | dockergen.1 | 2018/05/23 14:16:37 Error running notify command: nginx -s reload, exit status 1
nginx-proxy_1  | dockergen.1 | 2018/05/23 14:16:37 Contents of /etc/nginx/conf.d/default.conf did not change. Skippingnotification 'nginx -s reload'

When I use the browser to go to the virtual hosts, I get:

nginx-proxy_1  | nginx.1    | test-virtu 172.22.0.1 - - [23/May/2018:14:22:08 +0000] "GET / HTTP/1.1" 503 214 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0"
nginx-proxy_1  | nginx.1    | test-virtu 172.22.0.1 - - [23/May/2018:14:22:31 +0000] "GET / HTTP/1.1" 503 214 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0"

As soon as I get a solution, I'll try with docker-compose-letsencrypt-nginx-proxy-companion

Best.

evertramos commented 6 years ago

ok

because this repo was supposed to use with docker-compose-letsencrypt-nginx-proxy-companion

don´t know what to say...

In fact I have never tested fpm before

KZARCA commented 6 years ago

I'll try to find a solution, as soon as I get one, I'll inform you

marlosirapuan commented 6 years ago

I also tried, but no success.. I ended up using wp:latest (apache) 🤦‍♂️

evertramos commented 6 years ago

There is an error on the web-proxy... it has a PR open to fix it.. but I have not tried it yet... but I would get a way around it having another nginx container to router my request... it seems easier this way.

What you think?

@KZARCA @marlosirapuan

marlosirapuan commented 6 years ago

I saw a comment suggesting that too. But I have not tested it yet. It's working so well the way you show in the example I preferred to leave it that way. 😆

But I'll test it as soon as possible to see if it works!

marlosirapuan commented 6 years ago

@evertramos Hello! I tried. Unsuccessfully(with this PR). Opened a blank screen.

# blog.marlosirapuan.com
upstream blog.marlosirapuan.com {
                                # Cannot connect to network of this container
                                server 127.0.0.1 down;
                                ## Can be connected with "webproxy" network
                        # blog_wordpress_1
                        server 172.19.0.10:9000;
}
server {
        server_name blog.marlosirapuan.com;
        listen 80 ;
        access_log /var/log/nginx/access.log vhost;
        include /etc/nginx/vhost.d/default;
        location / {
                root   /var/www/html;
                include fastcgi_params;
                fastcgi_pass blog.marlosirapuan.com;
        }
}

docker-compose.yml:

services:
  db:
    image: mariadb:10.3.9
    restart: unless-stopped
    ports:
      - 3307:3306
    volumes:
      - ${STORAGE_MYSQL}:/var/lib/mysql
     # - ./configs/mysql:/etc/mysql/conf.d
    environment:
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
      MYSQL_DATABASE: ${MYSQL_DATABASE}
      MYSQL_USER: ${MYSQL_USER}
      MYSQL_PASSWORD: ${MYSQL_PASSWORD}

  wordpress:
    networks:
      - webproxy
      - default
    depends_on:
      - db
    image: wordpress:php7.2-fpm-alpine
    restart: unless-stopped
    volumes:
      - ${STORAGE_WP_CORE}:/var/www/html
      - ${STORAGE_WP_CONTENT}:/var/www/html/wp-content
      - ./configs/uploads.ini:/usr/local/etc/php/conf.d/uploads.ini
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_NAME: ${MYSQL_DATABASE}
      WORDPRESS_DB_USER: ${MYSQL_USER}
      WORDPRESS_DB_PASSWORD: ${MYSQL_PASSWORD}
      WORDPRESS_TABLE_PREFIX: ${WORDPRESS_TABLE_PREFIX}
      VIRTUAL_HOST: ${VIRTUAL_HOST}
      VIRTUAL_ROOT: /var/www/html
      VIRTUAL_PROTO: fastcgi

nginx image (proxy):

image: nginx:alpine

logs:

blog.marlosirapuan.com 181.221.255.219 - - [11/Sep/2018:20:11:21 +0000] "GET / HTTP/1.1" 200 5 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.81 Safari/537.36"

what you think? 🤔

evertramos commented 6 years ago

I need to test this.. but what I have did in one service wast to set up a new nginx behid the proxy to serve the app...

This is sort of how my custom nginx conf looks like:

server {
    index index.php index.html;
    server_name yourdomain.com;

    error_log  /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;

    root /var/www/html;

    client_max_body_size 100m;

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

    location ~ ^/.+\.php(/|$) {
        fastcgi_pass your_wordpress_container_name:9000;
        include fastcgi_params;
        fastcgi_read_timeout 600;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
}

I will try to test over the week, but if you could test putting up a new nginx container with your wordpress services, expose only this nginx container with virtual host without proto and test it, might work better this way as you have a very customizable nginx to do the job for you as you must.

marlosirapuan commented 6 years ago

Hmmm. Makes sense. I'll try this approach next week (because I'm busy right now) and come back here to show my results! 👊