我正在将nginx docker容器设置为php-fpm的反向代理。可能吗

时间:2019-04-04 05:07:57

标签: php docker nginx arm

我正在研究raspbberry pi(手臂架构),并且正在使用docker在非常轻量级的操作系统(HyperiotOS)上运行容器。我已经成功设置了nginx + php-fpm容器,如果该卷在两个容器上都装有代码,则由nginx config提供php文件。

现在我的问题是:我正试图将nginx设置为反向代理,这意味着我不希望nginx访问驱动器上的任何代码,我想将所有请求转发到php容器并显示结果。我尝试使用proxy_pass,但是没有用。有没有办法做到这一点 ?下面的代码示例。

我的docker撰写:

version: '3'
services:
  nginx:
    image: arm32v7/nginx:latest
    container_name: nginx
    restart: unless-stopped
    ports:
      - "8080:80"
    volumes:
      - ./conf.d:/etc/nginx/conf.d
      - ./logs:/var/log/nginx/
      - ./code:/code # this is what I want to get rid off
    networks:
      - webserver
  php:
    image: arm32v7/php:7.3-fpm
    expose:
      - "9000"
    restart: unless-stopped
    container_name: php-fpm
    volumes:
      - ./code:/code
    networks:
      - webserver
networks:
  webserver:
    driver: bridge

我的nginx配置:

server {
    listen 80;
    index index.php index.html;
    server_name raspberry.local;
    error_log  /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;
    root /code;

    location ~ \.php$ {
        try_files $uri /dev/null =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;
    }
}

现在在/ code文件夹中,我有带有PHP信息的index.php。 此配置运行良好,访问raspberry.local:8080后,我可以看到php信息页面。

但是,为了访问它,我在Nginx容器中安装了/ code。

- ./code:/code # this is what I want to get rid off

现在我要消除这种情况,因此我可以将nginx作为平衡器放置在其他地方,而无需访问代码。我想直接将请求代理到php容器。我尝试使用proxy_pass http://php:9000,但事情破了。从代码中“分离” nginx并充当独立代理的最佳方法是什么?有多种原因可以消除,如果可能的话,一个是生产类型构建。我无法共享需要烘焙的文件夹。我不希望两个容器都带有代码。如果可以的话,我可以将apache放入php容器并在其中代理nginx并消除fpm。

0 个答案:

没有答案