从Docker容器提供WordPress静态文件

我有一个WordPress的Docker容器,并使用nginx作为主机上的反向代理。

WP容器在端口32776上为WordPress提供服务,我的nginxconfiguration在主机上是这样的:

nginxconfiguration(主机)

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; } ... } 

nginxconfigurationINSIDE 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它会自动redirect到domain.com/blog/wp-content/themes/twentyseventeen/style.css/,并根据我的访问日志它试图finddomain.com/blog/wp-content/themes/twentyseventeen/style.css/index.php

我如何正确设置我的Nginxconfiguration文件?

当使用nginx反向代理时,你应该把你的静态文件放在那个nginx容器中

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

我build议使用volumes 或多构build阶段进行此设置