caddyserver / caddy

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
https://caddyserver.com
Apache License 2.0
57.6k stars 4.01k forks source link

how configure php silex framework with caddy #563

Closed cocodrino closed 8 years ago

cocodrino commented 8 years ago

Hi guys, first let me know if this is the best place for this kind of questions or must I only open tickets here for caddy isssues and ask this questions in stackoverflow

I´m currently using php silex, which is similar to node express or go gorilla router, basically I define my routes in an index file and this handle my request...

Here is how configure it for nginx, I guess than in caddy would be similar but I´ve had some troubles trying using bo

http://silex.sensiolabs.org/doc/web_servers.html

server {
    server_name domain.tld www.domain.tld;
    root /var/www/project/web;

    location / {
        # try to serve file directly, fallback to front controller
        try_files $uri /index.php$is_args$args;
    }

    # If you have 2 front controllers for dev|prod use the following line instead
    # location ~ ^/(index|index_dev)\.php(/|$) {
    location ~ ^/index\.php(/|$) {
        # the ubuntu default
        fastcgi_pass   unix:/var/run/php5-fpm.sock;
        # for running on centos
        #fastcgi_pass   unix:/var/run/php-fpm/www.sock;

        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param HTTPS off;

        # Prevents URIs that include the front controller. This will 404:
        # http://domain.tld/index.php/some-path
        # Enable the internal directive to disable URIs like this
        # internal;
    }

    #return 404 for all php files as we do have a front controller
    location ~ \.php$ {
        return 404;
    }

    error_log /var/log/nginx/project_error.log;
    access_log /var/log/nginx/project_access.log;
}``

I´d appreciate if you can give me a clue and even better ,include this info in the silex page would be awesome (I could open a ticket in the silex repo for add this)

thank you
abiosoft commented 8 years ago

Try this

domain.ltd, www.domain.ltd {
    fastcgi / unix:/var/run/php5-fpm.sock php

    rewrite {
        if {file} ends_with .php
        if {path} not_match ^/index\.php(/|$)
        status 404
    }

    rewrite {
        to {path} /index.php?{query}
    }

    log /var/log/nginx/project_access.log
    errors /var/log/nginx/project_error.log
}
mholt commented 8 years ago

Closing unless there's anything else.