@Andre548

Как настроить nginx?

Всем привет, хочу запустить проект в докере. Получаю ошибку ERR_TOO_MANY_REDIRECTS и в адресной строке выводит
https://domain/index.php/login , хотя должно быть https://domain/pl/login
мой nginx reverse proxy
server {

    server_name speedcut;

    root /www/speedcut/public;

    include h5bp/basic.conf;
    include h5bp/errors/custom_errors.conf;
    include h5bp/security/strict-transport-security.conf;

    charset utf-8;
    access_log  /var/log/nginx/speedcut.access.log  main;
    error_log   /var/log/nginx/speedcut.error.log   error;


    index  index.html index.htm;

    location / {
        proxy_pass http://localhost:8080;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        try_files $uri $uri/ /index.php?$query_string;
    }
   # location ~ \.php {
   #     include /etc/nginx/fastcgi_params;
   #     fastcgi_pass localhost:9000;
   # }

    listen 443 ssl http2; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
    include h5bp/ssl/ssl_engine.conf;
    include h5bp/ssl/policy_modern.conf;
    ssl_certificate /etc/letsencrypt/live/speedcut/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/speedcut/privkey.pem; # managed by Certbot


}

server {
    if ($host = webserver.dev) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

    server_name webserver.dev;

    listen 80;
    return 404; # managed by Certbot
}


и конфиг nginx в контейнере
server {
    listen   80 default_server; ## listen for ipv4; this line is default and implied
    #listen [::]:80 ipv6only=on;

    root /var/www/html/public;
    server_name app;
    index index.php;
    charset utf8;


    location /assets/
    {
        location ~ \.(?:js|json|ts|css|scss|woff(?:2)?|ttf|map|ico|html|xml|swf|flv|pdf|xls|htc|svg|gif|jpg|png|jpeg)$ {
            log_not_found off;
            expires 90d;
            gzip on;
            gzip_static on;
            gzip_http_version 1.1;
            gzip_comp_level 8;
            gzip_types text/plain text/css application/x-javascript text/javascript;
        }

        return 404;
    }

    location = /500.html {}

    location = /favicon.ico
    {
        log_not_found off;
        access_log off;
    }

    location = /robots.txt
    {
        allow all;
        log_not_found off;
        access_log off;
    }

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

    location ~ \.php$
    {
        try_files $uri =404;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_pass unix:/var/run/php/php5.6-fpm.sock;
    }
}
  • Вопрос задан
  • 146 просмотров
Решения вопроса 1
condor-bird
@condor-bird
Смотрите часть, где указано proxy_pass в location/ блоке. Для try_files установлено значение $uri $uri/ /index.php?$query_string, если запрошенный адрес не удается открыть, он перенаправит на /index.php?$query_string.
Но также если и на /index.php перенаправляет, отсюда и бесконечный цикл.
Конфиг должен быть примерно такой:

Nginx домена

server {
    listen 80;
    server_name domain.com;
    return 301 https://$server_name$request_uri;
}

server {
    listen 443 ssl;
    server_name domain.com;

    location / {
        proxy_pass http://localhost:8080;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }
}



Nginx в докере

server {
    listen 80;
    listen [::]:80;
    server_name _;
    root /var/www/domain.com/public;

    index index.php;

    charset utf-8;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    error_page 404 /index.php;

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }
}

Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы