Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
596 views
in Technique[技术] by (71.8m points)

nginx - 泊坞窗撰写:无法使用Nginx访问文件(docker compose: Can't access to files with nginx)

I'm learning docker and I need to make a container of nginx and another for php.

(我正在学习docker,我需要为Nginx和php创建一个容器。)

Apparently it's correct, but I cannot access the files.

(显然是正确的,但是我无法访问文件。)

I don't know if I'm doing something wrong or if I have a wrong site.conf file.

(我不知道我做错了什么,或者我有错误的site.conf文件。)

My docker-compose.yml file is:

(我的docker-compose.yml文件是:)

version: "3.7"

services:

  http:
    hostname: nginx_container
    domainname: mysite.local
    build: ./infrastructure/docker/nginx
    ports:
      - "8085:80"
    volumes:
      - ./src/www:/usr/share/nginx/html
      - ./src/site.conf://etc/nginx/conf.d/default.conf
    restart: always
    networks:
      - code-network

  php:
    build: ./infrastructure/docker/php
    volumes:
      - ./src/www:/usr/share/nginx/html
    restart: always
    networks:
      - code-network

networks:
    code-network:
        driver: bridge

The nginx Dockerfile is:

(Nginx Dockerfile是:)

FROM nginx:stable
MAINTAINER foo

The php Dockerfile is:

(php Dockerfile是:)

FROM php:7.3-fpm
MAINTAINER foo

The site.conf file is:

(site.conf文件为:)

server {
    listen 80;
    index index.php index.html;
    server_name localhost;
    error_log  /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;
    root /usr/share/nginx/html;

    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;
    }
}

and in the src/www path I have an index.html, and index.php and a php-status.php files with the same content:

(在src / www路径中,我有一个index.html,index.php和一个php-status.php文件,它们的内容相同:)

<?php

phpinfo();

But if I try to access to http://localhost:8085 or http://localhost:8085/index.php I get a ERR_EMPTY_RESPONSE

(但是,如果我尝试访问http:// localhost:8085http:// localhost:8085 / index.php,则会收到ERR_EMPTY_RESPONSE)

And if I try a http://mysite.local or http://mysite.local:8085 or http://mysite.local/index.php I get and ERR_NAME_NOT_RESOLVED

(如果我尝试使用http://mysite.localhttp://mysite.local:8085http://mysite.local/index.php,我会得到ERR_NAME_NOT_RESOLVED)

I haven't modified the hosts file, but the objective is reach to the index with the mysite.local, but if I can't reach it with localhost I can't reach it with mysite.local even if I add it to the hosts file.

(我没有修改hosts文件,但是目标是使用mysite.local到达索引,但是如果我无法通过localhost到达它,即使将其添加到mysite.local也无法到达mysite.local。主机文件。)

I've been all day trying to solve it, but I miss something and can't access to the php-info().

(我已经整日试图解决它,但是我错过了一些东西,无法访问php-info()。)

Can anybody help me please?

(有人可以帮我吗?)

used versions:

(使用的版本:)

  • Docker engine 19.03.5

    (Docker引擎19.03.5)

  • Docker compose 1.24.1

    (Docker撰写1.24.1)

  • Docker machine 0.16.2

    (Docker机器0.16.2)

  • macOS Mojave 10.14.6

    (macOS Mojave 10.14.6)

  ask by Alex translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...