Home > Net >  Nginx, WordPress 6, Docker and friendly url
Nginx, WordPress 6, Docker and friendly url

Time:07-15

I need some help... If i set up frendly url in WP, like /%postname% or /%postname%.html (docker image: wordpress:6.0-php7.4-apache) i receive 500 internal server error on blog item page (list works fine) and cant update posts from admin panel(((

if use default link format with id (first in list) - all works (update from admin panel and view on site)

Try to debug and saw that i'm not use index.php file from root diretory while request "/blog2/foo-bar/", so problem with nginx conf file (I think)

docker-compose:

version: '3'
services:
    nginx:
        image: container-registry.cloud.yandex.net/crp5sduab6n1r9hgpppp/main-site-nginx:1.0
        restart: always
        ports:
            - 80:80
            - 443:443
        logging:
            driver: 'json-file'
            options:
                max-size: '30m'
                max-file: '5'
        networks:
            - main-site-network
    wordpress_db:
        container_name: 'wp-db'
        image: mysql:5.7
        restart: always
        environment:
            MYSQL_ROOT_PASSWORD: *****
            MYSQL_DATABASE: wp
            MYSQL_USER:  wpu
            MYSQL_PASSWORD: *****
        networks:
            - main-site-network
        volumes:
            - db_data:/var/lib/mysql
    wordpress:
        container_name: 'wp'
        depends_on:
            - wordpress_db
        image: wordpress:6.0-php7.4-apache
        restart: always
        environment:
            WORDPRESS_DB_HOST: wordpress_db
            WORDPRESS_DB_USER: wpu
            WORDPRESS_DB_PASSWORD: ****
            WORDPRESS_DB_NAME: wp
        networks:
            - main-site-network
        volumes:
            - wordpress_data:/var/www/html
networks:
    main-site-network:
        driver: bridge
volumes:
    ftpdata:
    db_data: {}
    wordpress_data: {}

nginx.conf:

user nginx;
worker_processes 1;

error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;

events {
    worker_connections  1024;
}

http {

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    log_format main '$remote_addr - $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;

    client_header_timeout 60;
    client_body_timeout 60;
    send_timeout 120;
    proxy_read_timeout 90;
    proxy_connect_timeout 90;
    proxy_send_timeout 90;

    proxy_buffer_size 256k;
    proxy_buffers 32 256k;
    proxy_temp_file_write_size 256k;

    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $remote_addr;

    gzip on;
    gzip_min_length 4096;
    gzip_buffers 32 128k;
    gzip_types text/plain text/js text/css text/javascript application/javascript application/x-javascript application/json text/xml;

    client_header_buffer_size 1k;
    large_client_header_buffers 4 4k;

    sendfile on;
    tcp_nopush on;

    postpone_output 1460;

    keepalive_timeout 65;
    tcp_nodelay on;

  resolver 127.0.0.11 8.8.8.8 ipv6=off;

    server {
        listen *:80 default_server;
        server_name domain.tld;

    gzip on;
    gzip_min_length 4096;
    gzip_buffers 32 128k;
    gzip_types text/plain text/js text/css text/javascript application/javascript application/x-javascript application/json text/xml;

        add_header X-Content-Type-Options "nosniff";
        add_header Strict-Transport-Security max-age=31536000;

        client_max_body_size 500m;

        location ~ ^/wp-admin {
      return 307 https://$server_name/blog2$request_uri;
    }

        location /blog2/ {
      proxy_set_header Host $Host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $remote_addr;
      proxy_set_header X-Forwarded-Proto $scheme;
      proxy_set_header X-NginX-Proxy true;
      proxy_pass http://wordpress:80/;
    }
    }
}

CodePudding user response:

I think you need to add a block with additional location like for blog2

CodePudding user response:

Fix in above exsample (replace SUBFOLDER with your subpath):

docker-compose.yml

wordpress:
    volumes:
        - wordpress_data:/var/www/html/SUBFOLDER

nginx.conf

  location /SUBFOLDER {
    proxy_set_header Host $Host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_pass http://wordpress:80;
  }

and all work perfectly (plugins, backups and other)

  • Related