docker 运行laravel,nginx这样配置为何不可?

docker的nginx应该如何配置才可以运行项目。
本机电脑系统:mac
nginx配置如下如何修改

想要实现的效果:

docker 运行laravel,nginx要如何配置?

将localhost:8083/yxfxs/public 访问laravel 改为 yxfxs.test即可访问

nginx配置:

server {
    listen       80;
    server_name  localhost;

    location / {
        index  index.html index.htm index.php;
        try_files $uri $uri/ /index.php?$query_string;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    location ~ \.php$ {
        fastcgi_pass   php:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /www/$fastcgi_script_name;
        include        fastcgi_params;
    }

}

hosts配置。如下:

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1       localhost
255.255.255.255 broadcasthost
::1             localhost
127.0.0.1       content.test

127.0.0.1       AcronisDriveSearchPlugin
# Added by Docker Desktop
# To allow the same kube context to work on the host and the container:
127.0.0.1 kubernetes.docker.internal
# End of section

laravel 项目目录:

docker 运行laravel,nginx要如何配置?

docker 镜像:

docker 运行laravel,nginx要如何配置?

阅读 2.5k
1 个回答

启动 php的时候加上 -v 参数,把本地路径挂到镜像里,比如把 laravel项目挂到 /var/www/laravel 路径下面

docker run --name phpimagename -v "本地的laravel绝对路径:/var/www/laravel"  php:8-fpm

启动 nginx,

docker run -p "8083:80" nginx

修改nginx镜像中的配置,

fastcgi_pass   phpimagename:9000;
fastcgi_param  SCRIPT_FILENAME  /var/www/laravel/public$fastcgi_script_name;

访问 localhost:8083

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
宣传栏