繁体   English   中英

使用nginX和HTTPS下载index.php文件而不是呈现它

[英]Using nginX and HTTPS downloads the index.php file instead of rendering it

我在nginx中使用docker。

当我去:

http://www.mypage.com

一切都很好,但是当我添加HTTPS时,它实际上只是下载index.php。

日志中没有任何内容,因此我不确定从哪里开始修复此问题。

这是我的相关配置:

码头工人,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;

您的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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM