我正在尝试在docker中运行我的codeigniter项目。我在 docker-compose.yml 中有以下应用程序配置(下面仅显示了应用程序部分)
app:
build: .
volumes:
- .:/var/www/html/codeigniter/
depends_on:
- db
environment:
- POSTGRES_HOST=db
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=dummy
ports:
- 8080:81
var / www / html / codeigniter / app / nginx / default.conf 中的具有以下内容(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;
}
在运行 docker-compose up 命令时,它正在加载项目。但显示404的CSS和JS文件。 css文件夹路径为/ var / www / html / codeigniter / app / css /。我想念什么?
我的文件夹结构
codeigniter
├── app
│ ├── application
│ ├── css
│ ├── img
│ ├── js
│ ├── nginx
│ ├── system
│ ├── user_guide
│ └── vendor
│ └── Dockerfile
│ └── docker-composer.yml
请帮助。谢谢
答案 0 :(得分:0)
我遇到了这个问题,当我发现应该运行时,没有必要修改nginx conf:
docker stop $(docker ps -a -q)
和
docker rm $(docker ps -a -q)
要稍后再查看更改conf nginx之后的效果,然后运行:
docker-compose up --build
清除网络浏览器的缓存,Cookie和历史记录
我的conf文件:
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;
}
}
}