我这边docker已经装好使用的laradock镜像
1,配置宿主机nginx
cd /usr/local/openresty/nginx/conf/conf.d/
找到对应的配置文件:
增加配置
server {
listen 443 ssl;
#域名
server_name xxxx.com;
#请求日志目录
access_log logs/xxxx_access.log;
#错误日志目录
error_log logs/xxxxx_error.log;
#https证书配置目录
ssl_certificate ssl/xxxx.com/ssl.cert;
ssl_certificate_key ssl/xxxx.com/ssl.key;
#系统
location /xxxx_api/ {
proxy_set_header Host $proxy_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://xxxx_api.com:10080/;
}
}
2,新增本地host文件:
vi /etc/hosts
127.0.0.1 xxxx_api.com
3,进入docker 项目目录拉取代码
git clone git@项目代码仓库
4,修改docker内部nginx配置
进入到配置目录
cd /data/app/docker-php/nginx/sites
vi xxxx_api.conf
写入:
server {
listen 80;
server_name xxxx.com;
root /var/www/xxxx/public;
location / {
index index.php index.html error/index.html;
try_files $uri $uri/ /index.php?$query_string;
autoindex off;
}
location ~ .php(.*)$ {
#端口
fastcgi_pass laradock-php-fpm-1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^((?U).+.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
}
}
5,修改项目内的数据库,redis等配置 ,配置到docker内,也可以根据IP指定到宿主机的相应服务。
6,重启宿主机nginx和docker nginx
nginx -t
nginx -s reload
#docker nginx 重启
docer compose exec nginx bash
nginx -t
nginx -s reload
7,注意项目日志目录权限,composer install执行等操作。
8,访问项目