dongshijiao6890 2018-07-05 09:32 采纳率: 0%
浏览 308

css没有使用nginx在docker中加载

I am trying to run my codeigniter project in a docker. I have following app configuration in docker-compose.yml(only app part is shown below)

app:
  build: .
  volumes:
    - .:/var/www/html/codeigniter/
  depends_on:
    - db
  environment:
    - POSTGRES_HOST=db
    - POSTGRES_USER=postgres
    - POSTGRES_PASSWORD=dummy
  ports:
    - 8080:81

in var/www/html/codeigniter/app/nginx/default.conf has the following content(nginx conf)

server {
   listen 81 default_server;
   listen [::]:81 default_server;
   server_name localhost;

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

   location ~* \.(ico|css|js|gif|jpe?g|png)$ {}

   location / {
      try_files $uri $uri/ /index.php$is_args$args;
      include /etc/nginx/mime.types;
   }

   location ~* \.php$ {
      fastcgi_pass app:9000;
      fastcgi_index index.php;
      fastcgi_split_path_info ^(.+\.php)(.*)$;
      include fastcgi_params;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  }

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

while running docker-compose up command, it is loading the project. But showing 404 for css and js files. css folder path is /var/www/html/codeigniter/app/css/. What am I missing?

My folder structure

codeigniter
├── app
│   ├── application
│   ├── css
│   ├── img
│   ├── js
│   ├── nginx
│   ├── system
│   ├── user_guide
│   └── vendor
│   └── Dockerfile
│   └── docker-composer.yml

Please help. Thanks

  • 写回答

1条回答 默认 最新

  • dongzipu7517 2019-02-09 18:16
    关注

    I went through this problem and there was no use in tinkering with the nginx conf when I discovered that I should run:

    docker stop $(docker ps -a -q)
    

    and

    docker rm $(docker ps -a -q)
    

    To only later see effects after changing conf nginx and then run:

    docker-compose up --build
    

    Clear your web browser's cache, cookies, and history

    My conf file:

    worker_processes  1;  ## Default: 1
    
    worker_rlimit_nofile 8192;
    
    events {
      worker_connections  4096;  ## Default: 1024
    }
    
    http {
      include  mime.types;
    
      index    index.html index.htm index.php;
    
      default_type application/octet-stream;
      log_format   main '$remote_addr - $remote_user [$time_local]  $status '
        '"$request" $body_bytes_sent "$http_referer" '
        '"$http_user_agent" "$http_x_forwarded_for"';
    
      sendfile     on;
      tcp_nopush   on;
      server_names_hash_bucket_size 128; # this seems to be required for some vhosts
    
    
    
        server {
    
                listen *:80;
                server_name my.devcom;
    
                error_log  /var/log/nginx/error.log;
                access_log /var/log/nginx/access.log;
    
                root /www;
                index index.php;
    
                location = /favicon.ico {
                                log_not_found off;
                                access_log off;
                        }
    
                location = /robots.txt {
                                allow all;
                                log_not_found off;
                                access_log off;
                        }
    
                location / {
                    try_files $uri $uri/ /index.php?$args;
    
                }
    
    
                # redirect server error pages to the static page /50x.html
                #
                error_page 500 502 503 504 /50x.html;
                location = /50x.html {
                    root /var/lib/nginx/html;
                }
    
                # FastCGI 
                location ~ \.php$ {
                    try_files $uri =404;
                    fastcgi_split_path_info ^(.+\.php)(/.+)$;
                    fastcgi_pass php:9000;
                    fastcgi_index index.php;
                    fastcgi_intercept_errors on;
    
                    include fastcgi_params;
                    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                    fastcgi_param PATH_INFO $fastcgi_path_info;
                }
    
                location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
                    expires max;
                    log_not_found off;
            }
    
    
        }
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么