docker安装nginx

1.官方网址
https://hub.docker.com/_/nginx/ 
==================================================================== 

2. 拉取官方镜像
(1) docker pull nginx:1.15.8
(2)官方镜像配置文件目录结构:/etc/nginx
/etc/nginx   
|-- conf.d
|   |-- default.conf
|-- fastcgi_params
|-- koi-utf
|-- koi-win
|-- mime.types
|-- modules
|   |-- ngx_http_geoip_module-debug.so
|   |-- ngx_http_image_filter_module.so
|   |-- ngx_http_xslt_filter_module-debug.so
|   |-- ngx_stream_geoip_module.so
|   |-- ngx_http_geoip_module.so
|   |-- ngx_http_js_module-debug.so
|   |-- ngx_http_xslt_filter_module.so
|   |-- ngx_stream_js_module-debug.so
|   |-- ngx_http_image_filter_module-debug.so
|   |-- ngx_http_js_module.so
|   |-- ngx_stream_geoip_module-debug.so
|   |-- ngx_stream_js_module.so
|-- nginx.conf
|-- scgi_params
|-- uwsgi_params
|-- win-utf
(3)镜像用户:www-data,nginx
注:nginx.conf文件中通过引入了conf.d目录下的所有配置文件:include /etc/nginx/conf.d/*.conf;
====================================================================   

3.准备配置文件到宿主机以便于挂载
(1)从镜像中拷贝出配置文件(镜像中home目录是空的)
->拷贝nginx.conf文件:docker run --rm -v /etc/nginx:/home --privileged=true nginx:1.15.8 mv /etc/nginx/conf.d /home
->拷贝conf.d目录:docker run --rm -v /etc/nginx:/home --privileged=true nginx:1.15.8 mv /etc/nginx/nginx.conf /home
(2)修改配置文件/etc/nginx/conf.d/default.conf
location ~ \.php($|/) {
                root           /home/wwwroot;
                fastcgi_split_path_info ^(.+\.php)(.*)$;
                fastcgi_pass   php:9000;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                include        fastcgi_params;
}

==================================================================== 

4. 运行镜像
(1)在文件docker-compose.yml中添加运行项,再运行:docker-compose up -d nginx
nginx:
    image: nginx:1.15.8
    container_name: nginx
    privileged: true
    ports:
        - 80:80
    restart: always
    volumes:
        - /home/wwwroot:/home/wwwroot
        - /etc/nginx/conf.d:/etc/nginx/conf.d
        - /var/log/nginx:/var/log/nginx
    external_links:
        - php7:php

(2)直接运行:

docker run --name nginx -d -p 80:80 --restart always -v /home/wwwroot:/home/wwwroot -v /etc/nginx/conf.d:/etc/nginx/conf.d --link php7:php nginx:1.15.8

==================================================================== 

5.去掉index.php
location / {
                index  index.php;
                if (-e $request_filename) {
                                break;
                }
                if (!-e $request_filename) {
                                rewrite ^/(.*)$ /index.php/$1 last;
                                break;
                }
}
重启nginx:docker-compose restart nginx         

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值