【发布时间】:2019-08-17 23:30:34
【问题描述】:
我开始使用 docker 做一个小测试,以便设置我自己的服务器,但我遇到了一些问题。
我使用nginx-fpm 图像,其中包含设置服务器所需的大部分服务。
这是我的Dockerfile 我为了设置基本服务器而做的。我完美地构建了它,没有任何问题,并将其命名为nginx-custom-server。
Dockerfile
FROM "richarvey/nginx-php-fpm"
ADD /conf/simple-project.conf /etc/nginx/sites-available/simple-project.conf
RUN mkdir /srv/www/
RUN mkdir /LOGS/
RUN ln -s /etc/nginx/sites-available/simple-project.conf /etc/nginx/sites-enabled/simple-project.conf
RUN rm /etc/nginx/sites-enabled/default.conf
CMD ["/start.sh"]
我通过终端使用以下命令运行它。
docker run --name=server-stack -v /home/ismael/Documentos/docker-nginx/code:/srv/www -v /home/ismael/Documentos/docker-nginx/logs:/LOGS -p 80:80 -d nginx-custom-server:stack
在/srv/www 文件夹中,我有一个简单的hello world php。我想在本地机器上更改我的代码,并使用共享文件夹code 将其与 docker 容器同步。
nginx 日志是空的,所以我不知道出了什么问题。我在我的 conf 中设置了日志,但 nginx 没有创建它们,所以我认为我猜一般的 nginx conf 存在问题。
这是我用于我的 hello world 的 conf。我还将此服务器名称映射到主机的主机中。
simple-project.conf
server {
listen 0.0.0.0:80;
server_name simple-project.olive.com;
root /srv/www/simple-project/;
location / {
try_files $uri /index.php$is_args$args;
}
location ~ ^/index\.php(/|$) {
# the ubuntu default
fastcgi_pass /var/run/php-fpm.sock:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param APPLICATION_ENV int;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
}
location ~ \.php$ {
return 404;
}
error_log /LOGS/custom_error.log;
access_log /LOGS/custom_access.log;
}
编辑:当我尝试访问 docker 容器内的服务器时出错。
bash-4.4# wget localhost:80 > /tmp/output.html --2019-03-27 12:33:11-- http://localhost/ Resolving localhost... 127.0.0.1, ::1 连接到 localhost|127.0.0.1|:80... 失败:连接被拒绝。连接到 localhost|::1|:80... 失败:地址 无法使用。正在重试。
【问题讨论】: