Docker解决容器时区时间不一致
docker默认启动之后,进入容器或者在查看容器内日志的时候会发现,容器内的时区和服务器的时间不一样,相差一个时区,方便的解决方法可以在启动容器的时候绑定服务器的时区到容器,如下:
docker run ... -v /etc/timezone:/etc/timezone -v /etc/localtime:/etc/localtime nginx
/etc/timezone 是服务器时区;/etc/localtime 是服务器时间
Docker访问nginx+php报404的问题
docker访问一个明明存在的文件,但是访问出现404,刚开始使用docker的时候可能不大习惯,因为使用docker之后,你的nginx和php中的所有路径都需要写容器里的路径,而不是容器外的服务器目录路径,而我们在配置的nginx的root以及php的目录的时候就很可能忽略了这个地方的改变,导致访问的时候我们认为肯定存在的文件实际并不在docker里容器访问的目录里。docker中的root默认为:/usr/share/nginx/html,而php的root为/var/www/,容器启动时需要对目录进行挂载,但在配置文件中依然要使用容器内的地址。本文地址:http://www.04007.cn/article/707.html,未经许可,不得转载.
#docker启动nginx docker run --name nginx -d -p 80:80 \ -v /data01/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \ -v /data01/nginx/conf.d:/etc/nginx/conf.d \ -v /data01/nginx/log:/var/log/nginx \ -v /opt/www-data/tu.bce.com:/usr/share/nginx/html \ #时间挂载 -v /etc/timezone:/etc/timezone \ -v /etc/localtime:/etc/localtime \ nginx #nginx配置文件注意项 server{ listen 80; server_name test.04007.cn; #默认root为/usr/share/nginx/html/,框架根目录通常为./public root /usr/share/nginx/html/public; index index.html index.php; #注意此处的日志目录也是容器里的地址 access_log /var/log/nginx/access.log main; error_log /var/log/nginx/error.log; location / { try_files $uri /index.php?$args; } location ~ \.php$ { include fastcgi_params; fastcgi_pass 172.17.0.3:9000; #注意此处的php目录也会有所改变 fastcgi_param SCRIPT_FILENAME /var/www/public/$fastcgi_script_name; try_files $uri =404; } }本文地址:http://www.04007.cn/article/707.html,未经许可,不得转载.
本文地址:http://www.04007.cn/article/707.html 未经许可,不得转载. 手机访问本页请扫描右下方二维码.
![]() |
![]() |
手机扫码直接打开本页面 |