簡體   English   中英

從Docker容器提供WordPress靜態文件

[英]Serving WordPress static files from Docker container

我有一個WordPress Docker容器,並在主機上使用nginx作為反向代理。

在端口32776上為WordPress提供服務的WP容器,我的nginx配置在主機上是這樣的:

nginx配置(主機)

map $http_upgrade $connection_upgrade {
        default upgrade;
        '' close;
}
server {
...
    location /blog {
                    proxy_set_header Host $host;
                    proxy_set_header X-Real-IP $remote_addr;
                    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                    proxy_pass http://127.0.0.1:32776;
                    proxy_http_version 1.1;
                    proxy_set_header Upgrade $http_upgrade;
                    proxy_set_header Connection $connection_upgrade;
            }
...
}

Nginx配置INSIDE Docker

server {
    listen 0.0.0.0:80 default_server;
    listen [::]:80 default_server;

    root /var/www/html;

    # Add index.php to the list if you are using PHP
    index index.php index.html index.htm;

    server_name _;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini

        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
        fastcgi_index index.php;
        error_log ... error;
        access_log ...;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }
}

當我瀏覽到domain.com/blog時,它正在工作,但是沒有樣式和javascript文件。 因為當我轉到domain.com/blog/wp-content/themes/twentyseventeen/style.css時,它會自動重定向到domain.com/blog/wp-content/themes/twentyseventeen/style.css/並根據我的訪問日志它正在嘗試查找domain.com/blog/wp-content/themes/twentyseventeen/style.css/index.php

如何正確設置Nginx配置文件?

使用nginx反向代理時。您應將靜態文件放入該nginx容器中,例如

location /static{
    alias /usr/src/app/static;
}

我建議在此設置中使用volumes 或多構建階段

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM