问答

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

作者:admin 2021-05-05 我要评论

docker的nginx应该如何配置才可以运行项目。 本机电脑系统:mac nginx配置如下如何修改 想要实现的效果: 将localhost:8083/yxfxs/public 访问laravel 改为 yxfxs...

在说正事之前,我要推荐一个福利:你还在原价购买阿里云、腾讯云、华为云服务器吗?那太亏啦!来这里,新购、升级、续费都打折,能够为您省60%的钱呢!2核4G企业级云服务器低至69元/年,点击进去看看吧>>>)

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要如何配置?

###

启动 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

版权声明:本文转载自网络,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。本站转载出于传播更多优秀技术知识之目的,如有侵权请联系QQ/微信:153890879删除

相关文章
  • docker 运行laravel,nginx这样配置为

    docker 运行laravel,nginx这样配置为

  • laravel 分组后如何限制bookCode的数量

    laravel 分组后如何限制bookCode的数量

  • 求助:java AES加密 转php AES

    求助:java AES加密 转php AES

  • php如何连接java的mysql连接池?

    php如何连接java的mysql连接池?

腾讯云代理商
海外云服务器