###前提・実現したいこと
docker+nginxでindex.htmlファイルを更新したらすぐに反映されるようにしたいです。
###発生している問題
dockerでnginxを立ち上げたが、index.htmlを更新しても、ブラウザでアクセスしたときに更新が反映されない。
###該当のソースコード
app/docker/docker-compose.yml
yml
1version: '3' 2services: 3 nginx: 4 image: nginx 5 ports: 6 - 8080:80 7 volumes: 8 - ../public/:/usr/share/nginx/html/
app/public/index.html
html
1<!DOCTYPE html> 2<html lang="ja"> 3<head> 4 <meta charset="UTF-8" /> 5 <title>test</title> 6</head> 7<body> 8 <h1>test</h1> 9</body> 10</html>
###試したこと
以下のように変更して保存しても、変更が反映されない。
html
1<!DOCTYPE html> 2<html lang="ja"> 3<head> 4 <meta charset="UTF-8" /> 5 <title>test</title> 6</head> 7<body> 8 <h1>test2!</h1> 9</body> 10</html>
- chromeでF12→更新を右クリックして「キャッシュの消去とハード再読込」するとステータスコード304からステータスコード200になるが更新されない。
- vm上から
curl http://localhost:8080
しても更新されていないソースが見える。 docker stop $(docker ps -q)
docker rm $(docker ps -aq)
docker volume ls -q -f dangling=true | xargs docker volume rm
を行ったのち、docker-compose up
で立ち上げ直すが解決しない。- vagrant reloadでvmを再起動しても解決しない。
docker-compose run nginx /bin/bash
でログインし、cat index.html
としても解決しない。docker-compose run nginx /bin/bash
でログインし、touch index.html
で更新日時を更新しても解決しない。- index.html → _index.htmlとリネームすると、404となる。ファイルの追加・削除は正常な模様。
- _index.htmlにアクセスすると、変更後のソースが読み込まれる。
- _index.html → index.htmlにリネームすると、変更後のソースが読み込まれて解決する。
一応の解決手順は見つかりましたが、リネーム → アクセス → リネームと作業が多いです。
回避方法、また原因など教えていただけたら幸いです。
###補足情報(言語/FW/ツール等のバージョンなど)
- chrome 61.0.3163.91(Official Build) (64 ビット)
- windows10
- virtualbox 5.1.26
- vagrant 1.9.7
- bento/ubuntu-16.04
- Docker version 17.06.2-ce, build cec0b72
- docker-compose version 1.16.1, build 6d1ac21
追記・サーバ設定
修正依頼ありがとうございます。nginxの設定ファイルは以下になります。
配布コンテナから特に変更はしていません。
/etc/nginx/nginx.conf
config
1 2user nginx; 3worker_processes 1; 4 5error_log /var/log/nginx/error.log warn; 6pid /var/run/nginx.pid; 7 8 9events { 10 worker_connections 1024; 11} 12 13 14http { 15 include /etc/nginx/mime.types; 16 default_type application/octet-stream; 17 18 log_format main '$remote_addr - $remote_user [$time_local] "$request" ' 19 '$status $body_bytes_sent "$http_referer" ' 20 '"$http_user_agent" "$http_x_forwarded_for"'; 21 22 access_log /var/log/nginx/access.log main; 23 24 sendfile on; 25 #tcp_nopush on; 26 27 keepalive_timeout 65; 28 29 #gzip on; 30 31 include /etc/nginx/conf.d/*.conf; 32} 33
/etc/nginx/conf.d/default.conf
config
1server { 2 listen 80; 3 server_name localhost; 4 5 #charset koi8-r; 6 #access_log /var/log/nginx/host.access.log main; 7 8 location / { 9 root /usr/share/nginx/html; 10 index index.html index.htm; 11 } 12 13 #error_page 404 /404.html; 14 15 # redirect server error pages to the static page /50x.html 16 # 17 error_page 500 502 503 504 /50x.html; 18 location = /50x.html { 19 root /usr/share/nginx/html; 20 } 21 22 # proxy the PHP scripts to Apache listening on 127.0.0.1:80 23 # 24 #location ~ \.php$ { 25 # proxy_pass http://127.0.0.1; 26 #} 27 28 # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 29 # 30 #location ~ \.php$ { 31 # root html; 32 # fastcgi_pass 127.0.0.1:9000; 33 # fastcgi_index index.php; 34 # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; 35 # include fastcgi_params; 36 #} 37 38 # deny access to .htaccess files, if Apache's document root 39 # concurs with nginx's one 40 # 41 #location ~ /\.ht { 42 # deny all; 43 #} 44} 45
回答2件
あなたの回答
tips
プレビュー