1:安装Laradock
参考官方文档:
https://laradock-docs.linganmin.cn/zh/getting-started/
通过git下载: git clone https://github.com/laradock/laradock.git
下载成功后进入 laradock 文件夹并复制 env-example 为 .env为配置文件
2:下载启动容器
docker-compose up -d nginx mysql redis //可一次性启动关联容器,本地没有镜像时会自动下载
查看容器是否启动成功
docker-compose ps
3:配置nginx
进入nginx容器
docker-compose exec nginx bash
nginx的配置文件在容器中的 /etc/nginx 目录下
首先在改目录下创建一个vhost目录,多项目可以把所有的conf文件保存在这个地方
然后cp一份nginx.conf做备份
cp nginx.conf nginx.conf.cp
然后注释掉nginx.conf里面的 include /etc/nginx/sites-available/*.conf;
添加上include /etc/nginx/vhost/*.conf;
user www-data; worker_processes 4; pid /run/nginx.pid; daemon off; events { worker_connections 2048; multi_accept on; use epoll; } http { server_tokens off; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 15; types_hash_max_size 2048; client_max_body_size 20M; include /etc/nginx/mime.types; default_type application/octet-stream; access_log /dev/stdout; error_log /dev/stderr; gzip on; gzip_disable "msie6"; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers 'ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:ECDHE-ECDSA-DES-CBC3-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA:!DSS'; include /etc/nginx/conf.d/*.conf; #include /etc/nginx/sites-available/*.conf; 注释掉这行 include /etc/nginx/vhost/*.conf; #添加上这行 open_file_cache off; # Disabled for issue 619 charset UTF-8; }
接下来把/etc/nginx/sites-available/目录下的default.conf复制一份到vhost文件夹下,多项目看根据网址命名,如test.conf
cp /etc/nginx/sites-available/default.conf /etc/nginx/vhost/test.conf
修改test.conf为:
server { listen 80; #删掉default_server #listen [::]:80 default_server ipv6only=on; 注释掉这行 # For https # listen 443 ssl default_server; # listen [::]:443 ssl default_server ipv6only=on; # ssl_certificate /etc/nginx/ssl/default.crt; # ssl_certificate_key /etc/nginx/ssl/default.key; server_name test.cc; root /var/www/项目路径/public; index index.php index.html index.htm; location / { try_files $uri $uri/ /index.php$is_args$args; } location ~ \.php$ { try_files $uri /index.php =404; fastcgi_pass php-upstream; fastcgi_index index.php; fastcgi_buffers 16 16k; fastcgi_buffer_size 32k; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; #fixes timeouts fastcgi_read_timeout 600; include fastcgi_params; } location ~ /\.ht { deny all; } location /.well-known/acme-challenge/ { root /var/www/letsencrypt/; log_not_found off; } }
接下来exit退出容器并重新启动nginx容器
docker-compose restart nginx
查看nginx 是否启动 laradock ps 如果看到 laradock_nginx_1 就可以了
配置一下域名信息
C:\Windows\System32\drivers\etc\hosts
127.0.0.1 test.cc