laravel - 普通 HTTP 请求被发送到 HTTPS 端口报错 Docker nginx

标签 laravel docker nginx

我试图通过 http://localhost:8343/ 访问我的服务器,但它总是显示错误:

400 Bad Request

The plain HTTP request was sent to HTTPS port

nginx/1.14.2

这是我对 docker-compose.yml 的配置。

/*other configurations*/
services:

    pages:
        build:
            context: .
            dockerfile: ./pages/Dockerfile
        container_name: proj_idcf_pages_1
        ports:
            - "8180:80"
            - "8343:443"
        environment:
            - TZ=Asia/Tokyo
            - LA_PROJECT_DIR=laravel
        depends_on:
            - php7
        volumes:
            - ../service/pages/:/var/www/
            - ./ssl_key/:/etc/nginx/ssl_key
        networks:
            - proj_default
/*other configurations*/

页面/Dockerfile

FROM centos:centos7
FROM nginx:1.14.2

COPY pages/default.conf /etc/nginx/conf.d/default.conf

RUN sed -i -e "s/access_log .*;$/access_log  \/dev\/stdout;/g" /etc/nginx/nginx.conf
RUN sed -i -e "s/error_log .*;$/error_log  \/dev\/stderr debug;/g" /etc/nginx/nginx.conf

CMD ["nginx", "-g", "daemon off;"]

pages/default.conf

server {
    listen 80;
    rewrite ^(.*)$ http://localhost:8343$1 permanent;
}

server {
    listen 8343 ssl;
    listen 443 ssl;
    index index.php;
    server_name localhost:8180;
    error_log  /dev/stderr debug;
    access_log  /dev/stdout;
    root /var/www/laravel/public;

    ssl_certificate /etc/nginx/ssl_key/localhost.pem;
    ssl_certificate_key /etc/nginx/ssl_key/localhost.key;

    location / {
            try_files $uri $uri/ /index.php$is_args$args;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass php7:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;

        add_header my_string 'start';
        add_header $request_filename $request_filename;
        add_header my_document_root $document_root;
        add_header fastcgi_script_name $fastcgi_script_name;
        add_header my_fastcgi_path_info $fastcgi_path_info;
        add_header my_string_2 ‘end’;
    }
/*other settings*/

谁能帮我解决这个问题?我坚持了好几天:(

最佳答案

在你的 docker-compose.yaml ->

ports:
   - "8180:80"  
   - "8343:443" <------ Here you bind the host port 8343 to container's port 443

在 nginx 配置文件中 ->

server {
    listen 8343 ssl;
    listen 443 ssl; <------ you configured that port to listen https traffic

所以你要么访问http://localhost:8180https://localhost:8343

关于laravel - 普通 HTTP 请求被发送到 HTTPS 端口报错 Docker nginx,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57901036/

相关文章:

php - Laravel 和 CKEditor 提交表单时出错

php - Laravel 删除应用程序文件夹(根目录)中的文件

docker - 从docker-compose连接到不同堆栈上的服务

php - nginx req limit & failure2ban & cloudflare 大型攻击

node.js - nginx tcp SYN 数据包未收到 ACK

java - 无法从Java中的nginx反向代理获取远程IP

php - 如何在 LARAVEL 中指定表单名称

laravel - 在 Ubuntu 上使用 Sail 和 PhpStorm 在 Laravel 8 上运行 Xdebug

docker - 如何跟踪所有 docker 容器的日志?

docker - 将大文件添加到Docker构建中会导致EOF异常