亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用 docker nginx 映像時我將 index.php 放在哪里

使用 docker nginx 映像時我將 index.php 放在哪里

PHP
達令說 2023-07-15 15:34:30
我找不到放置文件 index.php 的位置,以便 ngnix 可以解釋我的文件。所有容器都在工作,當我把localhost:8080nginx 工作時這是我的 docker-compose.ymlweb:  image: nginx  volumes:   - ./templates:/etc/nginx/templates  ports:   - "8080:8080"  environment:   - NGINX_HOST=foobar.com   - NGINX_PORT=8080php:       image: php:7.0-fpm       expose:           - 9000       volumes_from:           - app       links:           - elasticapp:       image: php:7.0-fpm       volumes:           - .:/srcelastic:       image: elasticsearch:2.3       volumes:         - ./elasticsearch/data:/usr/share/elasticsearch/data         - ./elasticsearch/logs:/usr/share/elasticsearch/logs       expose:         - "9200"       ports:         - "9200:9200"誰能幫我嗎
查看完整描述

1 回答

?
搖曳的薔薇

TA貢獻1793條經驗 獲得超6個贊

您需要為 PHP 和 Nginx docker 鏡像安裝相同的卷。


version: '3'

services:

  nginx:

    image: nginx:alpine

    volumes:

      - ./app:/app

      - ./nginx-config/:/etc/nginx/conf.d/

    ports:

      - 80:80

    depends_on:

      - php

  php:

    image: php:7.3-fpm-alpine

    volumes:

     - ./app:/app


在上面的撰寫文件中,代碼放置app在主機的文件夾下。



├── app

│   ├── helloworld.php

│   └── index.php

├── docker-compose.yml

└── nginx-config

    └── default.conf

您的 Nginx 配置應該使用 docker 服務網絡來連接 php-fpm 容器。


server {

    index index.php index.html;

    server_name php-docker.local;

    error_log  /var/log/nginx/error.log;

    access_log /var/log/nginx/access.log;

    root /app/;


    location ~ \.php$ {

        try_files $uri =404;

        fastcgi_split_path_info ^(.+\.php)(/.+)$;

        fastcgi_pass php:9000;

        fastcgi_index index.php;

        include fastcgi_params;

        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

        fastcgi_param PATH_INFO $fastcgi_path_info;

    }

}

或者你可以嘗試 Github 上的工作示例。


git clone https://github.com/Adiii717/dockerize-nginx-php.git

cd dockerize-nginx-php;

docker-compose up

現在打開瀏覽器


http://localhost/helloworld.php


查看完整回答
反對 回復 2023-07-15
  • 1 回答
  • 0 關注
  • 150 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號