Nginx

帶有 wordpress/mysql/nginx 的 Docker,wordpress 中沒有樣式

  • January 23, 2018

所以我試圖用docker-compose. 我的目標是使用 nginx 來執行 wordpress-fpm。到目前為止,這是我的docker-compose.yml

version: '3'

services:
   nginx:
       image: nginx
       links:
           - wordpress
       ports:
           - 80:80
           - 443:443
       volumes:
           - ./nginx_config_content:/etc/nginx/conf.d
           - ./wordpress:/var/www/html
       restart: always

   wordpress:
       image: wordpress:4.9.2-php7.0-fpm
       links:
           - wp_db:mysql
       volumes:
           - ./wordpress:/var/www/html
       environment:
           WORDPRESS_DB_PASSWORD: "aqwe123"
       restart: always

   wp_db:
       image: mariadb
       volumes:
           - ./db-data:/var/lib/mysql
       environment:
           MYSQL_ROOT_PASSWORD: "aqwe123"
       restart: always

我的 nginx wordpress.conf

server {
      listen 80;
      server_name test.io;

      root /var/www/html;
      index index.php;

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

      location ~ \.php$ {
          try_files $uri =404;
      fastcgi_split_path_info ^(.+\.php)(/.+)$;
      fastcgi_pass wordpress:9000;
      fastcgi_index index.php;
      include fastcgi_params;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
      fastcgi_param PATH_INFO $fastcgi_path_info;
      }
}

一切都完美地連接在一起,但是當我從另一台電腦上打開網站時,http://192.168.1.161我得到了這個:

WordPress

Wordpress,但沒有樣式。我檢查了頁面原始碼,我可以看到 css 指向一個有效的路徑,比如<link rel='stylesheet' id='install-css' href='http://192.168.1.161/wp-admin/css/install.min.css?ver=4.9.2' type='text/css' media='all' />鍊接工作,css 文件確實存在。我已經嘗試解決這個問題好幾個小時了,我懷疑 nginx 配置文件失去了一些東西,但我找不到什麼。任何幫助將不勝感激。

將此添加到您的伺服器塊之外:

http { 
   include /etc/nginx/mime.types;
}

它應該成功載入呈現視圖所需的文件。

引用自:https://serverfault.com/questions/893706