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;
            }
    
    
        }
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP