我在nginx上使用docker。
当我去:
一切都很好,但是当我添加HTTPS时,它实际上只是下载index.php。
日志中没有任何内容,因此我不确定从哪里开始解决此问题。
这是我的相关配置:
Docker-compose.yml:
php:
image: myImage
ports:
- "9000:9001"
volumes:
- home/me/my-site/:/var/www/symfony:cached
- ./logs/symfony:/var/www/symfony/var/log:cached
extra_hosts:
- "docker-host.localhost:127.0.0.1"
- "otherhost:10.5.221.132"
nginx:
build: ./nginx
ports:
- "80:80"
- "443:443"
links:
- php
volumes:
- ./logs/nginx:/var/log/nginx:cached
- /home/me/my-site/:/var/www/symfony:cached
- ./nginx/my-site.com.crt:/etc/nginx/my-site.com.crt
- ./nginx/my-site.com.key:/etc/nginx/my-site.com.key
我的dockerfile:
FROM alpine:3.8
RUN apk add --update nginx
RUN rm -rf /var/cache/apk/* && rm -rf /tmp/*
ADD nginx.conf /etc/nginx/
ADD symfony.conf /etc/nginx/conf.d/
ADD fastcgi_params /etc/nginx/
ADD my-site.com.crt /etc/nginx/
ADD my-site.com.key /etc/nginx/
RUN echo "upstream php-upstream { server php:9000; }" > /etc/nginx/conf.d/upstream.conf
RUN adduser -D -g '' -G www-data www-data
CMD ["nginx"]
EXPOSE 80
EXPOSE 443
我的nginx.conf
user www-data;
worker_processes 4;
pid /run/nginx.pid;
events {
worker_connections 2048;
multi_accept on;
use epoll;
}
http {
server_tokens off;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 15;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log off;
error_log off;
gzip on;
gzip_disable "msie6";
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
open_file_cache max=100;
client_body_temp_path /tmp 1 2;
client_body_buffer_size 256k;
client_body_in_file_only off;
server {
listen 443 ssl;
server_name symfony.localhost;
ssl_certificate /etc/nginx/my-site.com.crt;
ssl_certificate_key /etc/nginx/my-site.com.key;
root /var/www/symfony/public/;
index index.php;
}
}
daemon off;
答案 0 :(得分:1)
您的nginx配置中没有任何php处理,您需要类似以下内容来收听php文件
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
更多信息https://www.nginx.com/resources/wiki/start/topics/examples/phpfcgi/#connecting-nginx-to-php-fpm