0

我有一个可以工作的nginx 反向代理,它已经可以工作并处理许多不同的网站(请参阅下面的工作配置文件)。

不,我有一个新的测试子域,我正在测试kirby-cms,它通常与 apache 配合得最好(或者至少创建者只真正关心 apache),但是文档和支持论坛为 nginx 配置提供了一些建议.

default.confjwilder从反向代理生成的默认模板/etc/nginx/conf.d如下所示:

# sub.domain.tld
upstream sub.domain.tld-upstream {
                # Cannot connect to network of this container
                server 127.0.0.1 down;
                ## Can be connected with "nginxproxy_default" network
            # name_subdomain_1
            server xxx.xx.0.2:80;
}
server {
    server_name sub.domain.tld;
    listen 80 ;
    access_log /var/log/nginx/access.log vhost;
    # Do not HTTPS redirect Let'sEncrypt ACME challenge
    location ^~ /.well-known/acme-challenge/ {
        auth_basic off;
        auth_request off;
        allow all;
        root /usr/share/nginx/html;
        try_files $uri =404;
        break;
    }
    location / {
        return 301 https://$host$request_uri;
    }
}
server {
    server_name sub.domain.tld;
    listen 443 ssl http2 ;
    access_log /var/log/nginx/access.log vhost;
    ssl_session_timeout 5m;
    ssl_session_cache shared:SSL:50m;
    ssl_session_tickets off;
    ssl_certificate /etc/nginx/certs/sub.domain.tld.crt;
    ssl_certificate_key /etc/nginx/certs/sub.domain.tld.key;
    ssl_dhparam /etc/nginx/certs/sub.domain.tld.dhparam.pem;
    ssl_stapling on;
    ssl_stapling_verify on;
    ssl_trusted_certificate /etc/nginx/certs/sub.domain.tld.chain.pem;
    add_header Strict-Transport-Security "max-age=31536000" always;
    include /etc/nginx/vhost.d/default;
    location / {
        root   /var/www/public;
        include fastcgi_params;
        fastcgi_pass sub.domain.tld-upstream;
        include /etc/nginx/vhost.d/sub.domain.tld_location;
    }
}

我应该从以下文档中添加什么kirby

server {
  listen 8080; # Can be omitted if Nginx runs on Port 80
  index index.php index.html;
  server_name localhost; # Adjust to your domain setup
  root /usr/share/nginx/html; # Adjust to your setup

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

  location ~* \.php$ {
    try_files $uri =404;
    fastcgi_pass php:9000; # Adjust to your setup
    include fastcgi.conf;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_param PATH_INFO $fastcgi_path_info;
    fastcgi_param SERVER_PORT 8080; # Only needed if external port is different from the listen port
  }
}

也许第一部分可以省略,但位置部分似乎很重要。不幸的是,不可能只覆盖默认部分。我应该怎么办?

我已经多次修改了上面的代码。目前它看起来像这样:

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

  location ~* \.php$ {
    try_files $uri =404;
    fastcgi_pass localhost:9001;
    include fastcgi.conf;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_param PATH_INFO $fastcgi_path_info;
 # fastcgi_param SERVER_PORT 9001; # Only needed if external port is different from the listen port
  }

我的柯比Dockerfile看起来像这样:

FROM php:7.4-fpm

# Install packages: web server & PHP plus extensions
RUN apt-get update && apt-get install -y \
  git \
  curl \
  libpng-dev \
  libonig-dev \
  zip \
  unzip

RUN apt-get clean && rm -rf /var/lib/apt/lists/*

RUN docker-php-ext-install pdo_mysql mbstring exif bcmath gd

COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
COPY composer.json composer.lock /var/www/html/
RUN composer install

WORKDIR /var/www/html

USER $user

docker-compose.yml


version: '3'

services:

  name_subdomain:
    build:
      context: .
      dockerfile: Dockerfile
    image: myimage-image
    restart: always
    networks:
      - proxy-tier
      - kirby
    ports:
      - 9001:80
    expose:
      - 9001
    environment:
      - VIRTUAL_HOST=sub.domain.tld
      - VIRTUAL_PROTO=fastcgi
      - VIRTUAL_PORT=80
      - VIRTUAL_ROOT=/var/www/html
      - VIRTUAL_NETWORK=nginx-proxy
      - LETSENCRYPT_HOST=sub.domain.tld
      - LETSENCRYPT_EMAIL=mymail@gmail.com
    volumes:
      - ./:/var/www/html

networks:
  kirby:
  proxy-tier:
    external:
      name: nginxproxy_default

最后docker-compose.yml是代理的配置:

version: '2'

services:

  nginx-proxy:
    image: jwilder/nginx-proxy:alpine
    container_name: nginx-proxy
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - "/etc/nginx/vhost.d"
      - "/usr/share/nginx/html"
      - "/var/run/docker.sock:/tmp/docker.sock:ro"
      - ./certs:/etc/nginx/certs:ro
      - ./letsencrypt-acme:/etc/acme.sh
      - /srv/www/production/name.de/sub.domain.tld_location:/etc/nginx/vhost.d/sub.domain.tld_location:ro
    restart: always

  letsencrypt-nginx-proxy-companion:
    image: nginxproxy/acme-companion
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock:ro"
      - ./certs:/etc/nginx/certs:rw
      - ./letsencrypt-acme:/etc/acme.sh
    volumes_from:
      - "nginx-proxy"
    restart: always

我已经尝试了很多小时和几天来让它工作,但我无法让它运行起来。

当前使用显示的设置,404 中的域错误没有内容 nginx.1 | sub.domain.tld xx.xxx.xxx.xxx - - [17/Aug/2021:17:29:20 +0000] "GET / HTTP/2.0" 404 556 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/xx.xxx.xxx.xxx Safari/537.36"

4

0 回答 0