在docker-nginx-php服务器上运行2个站点

时间:2016-09-25 15:07:52

标签: php amazon-web-services nginx docker containers

我正在使用Docker并使用nginx和mysql提供PHP API服务器。现在我正在尝试添加一个单独的静态网站,但未能通过修改 nginx.conf 来实现。以下是我的文件夹结构。

+ images
|+ php
|-- Dockerfile
||+ app
||-+ public
|||-- index.php
||+ home <-- TRYING TO GET THIS WORKING (Same level as app folder)
||-- index.html  <-- TRYING TO THIS WORKING 
|+ nginx
|-- nginx.conf
|-- Dockerfile
- README.md
- docker-compose.yml

这是我的nginx conf。

server {
  listen 80;
  server_name api.example.com;
  root /app/public;
  index index.php index.htm index.html;

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

  location /index.php {
      include fastcgi_params;
      fastcgi_connect_timeout 10s;
      fastcgi_read_timeout 10s;
      fastcgi_buffers 256 4k;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
      fastcgi_pass php:9000;
  }

    add_header Access-Control-Allow-Origin "*";
    add_header Access-Control-Allow-Methods "GET, OPTIONS";
    add_header Access-Control-Allow-Headers "origin, authorization, accept";
}

server {
    listen 80;
    server_name example.com www.example.com;
    root /home;
    index index.htm index.html

    location / {
        try_files $uri $uri/ /index.html;
    }

}

我可以访问api.example.com,一切正常。但是当我访问example.com时,它显示 404未找到。 nginx / 1.114 (它与docker-compose.yml有什么关系吗?)

谢谢!

0 个答案:

没有答案