最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - Caddy php_fastcgi give no result - Stack Overflow

programmeradmin0浏览0评论

Im currently using nginx as a reverse proxy, And i wanted to try Caddy to do the same !

To explain 1 have 2 services : 1php and 1go

The php is a backend that you use by calling /api/<.....> The golang is also a backend that you use by valling /api/device/position

Both start with the same /api ex: localhost/api/login localhost/api/device/position

This nginx conf is working

upstream php_backend {
    server back:9000;
}
server {
    listen 80;
    server_name ${NGINX_BACKEND_DOMAIN};

    root /var/www/symfony/public; 
    location / {
        try_files $uri /index.php$is_args$args;
    }

    location ~ ^/index\.php(/|$) {
        if ($request_method = 'OPTIONS') {
            add_header 'Access-Control-Allow-Origin' '*' always;
            add_header 'Access-Control-Allow-Methods' 'GET, POST, DELETE, OPTIONS, PUT, PATCH' always;
            add_header 'Access-Control-Allow-Headers' 'Authorization,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
            add_header 'Access-Control-Max-Age' 1728000 always;
            add_header 'Content-Type' 'text/plain; charset=utf-8' always;
            add_header 'Content-Length' 0 always;
            return 204;
        }
        
        fastcgi_pass php_backend;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param DOCUMENT_ROOT $document_root;
        internal;
    }

    location ~ \.php$ {
        return 404;
    }

    location /api/device/position {
        proxy_pass http://ping-service;
        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;
    }

    error_log /dev/stdout info;
    access_log /var/log/nginx/project_access.log;
}

And my not working Caddy config

:{$PORT} {
    # access logs
    log {
        format json # set access log format to json mode
    }

        php_fastcgi * wimova-connect-back:9000 {
            root /var/www/symfony/public
        }
    
    # handle /api/device/position requests
    handle /api/device/position {
        reverse_proxy http://ping-service {
            # configure load balancing settings
            import lb_settings

            # configure passive health checks
            import passive_health_checks

            # sets the Host header to the header to the dynamic name and port options
            header_up Host {upstream_hostport}
        }
    }
}

The /api/device/position is working well ! But the rest is not :\

Thanks for your help

发布评论

评论列表(0)

  1. 暂无评论