MichaelThessel / pwx

Online password exchange service
https://pwx.michaelthessel.com
MIT License
41 stars 20 forks source link

php POST can't create the link folder and the temporary file for the password (nginx / php-fpm) #54

Closed wilf1rst closed 8 years ago

wilf1rst commented 8 years ago

Hello, I tried to install my own pwx instance for work purpose. For testing purpose I disabled ssl mandatory from you app/config.php file. I use nginx as a web server with the following conf (example.com is replaced by my organization domain):

server {
    listen 80;
    server_name pwx.example.com;

    access_log /var/log/nginx/access-pwx.log;
    error_log /var/log/nginx/error-pwx.log;

    root /var/www/pwx/web;
    index index.php;

    location ~* \.php$ {
        try_files $uri =404;
        include fastcgi.conf;
        fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
        fastcgi_index index.php;
    }
}

I assume that the POST is not working and failed to create the temporary file in link folder. I create the web/link folder, make my web server group the owner of this folder (and chmod 777 it to be sure for the test …). But I still have the same error:

NGINX LOG

==> access-pwx.log<==
[15/Mar/2016:14:51:49 +0100] "POST / HTTP/1.1" 302 320 "http://pwx.example.com/" "Mozilla/5.0" (X11; Fedora; Linux x86_64; rv:44.0) Gecko/20100101 Firefox/44.0"

==> error-pwx.log <==
2016/03/15 14:51:49 [error] 16266#0: *46 open() "/var/www/pwx/web/link/3662178eab" failed (2: No such file or directory), client: 1.2.3.4 server: pwx.example.com, request: "GET /link/3662178eab HTTP/1.1", host: "pwx.example.com", referrer: "http://pwx.example.com/"

==> access-pwx.log <==
[15/Mar/2016:14:51:49 +0100] "GET /link/3662178eab HTTP/1.1" 404 168 "http://pwx.example.com/" "Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:44.0) Gecko/20100101 Firefox/44.0"

LOG/APP.LOG [2016-03-15 14:51:43.172076] pwx.INFO: Matched route "GET_". {"route_parameters":{"_controller":"app.default_controller:indexAction","route":"GET"},"requesturi":"http://pwx.example.com/"} {"clientIp":"1.2.3.4","token":"56e8136f279c4"} [2016-03-15 14:51:43.172647] pwx.INFO: > GET / [] {"clientIp":"1.2.3.4","token":"56e8136f279c4"} [2016-03-15 14:51:43.295656] pwx.INFO: < 200 [] {"clientIp":"1.2.3.4","token":"56e8136f279c4"} [2016-03-15 14:51:43.296611] pwx.DEBUG: Script executed in 169.605ms. {"msExecTime":169.605,"method":"GET","path":"/"} {"clientIp":"1.2.3.4","token":"56e8136f279c4"} [2016-03-15 14:51:49.264898] pwx.INFO: Matched route "POST". {"route_parameters": {"_controller":"app.default_controller:indexPostAction","route":"POST"},"request_uri":"http://pwx.example.com/"} {"clientIp":"1.2.3.4","token":"56e813753f255"} [2016-03-15 14:51:49.265250] pwx.INFO: > POST / [] {"clientIp":"1.2.3.4","token":"56e813753f255"} [2016-03-15 14:51:49.379064] pwx.INFO: < 302 /link/3662178eab [] {"clientIp":"1.2.3.4","token":"56e813753f255"} [2016-03-15 14:51:49.379964] pwx.DEBUG: Script executed in 143.301ms. {"msExecTime":143.301,"method":"POST","path":"/"} {"clientIp":"1.2.3.4","token":"56e813753f255"}

Do you have any clue ?

Bests regards.

wilf1rst commented 8 years ago

I answer myself... For nginx I have to convert the web/.htaccess rules. Using this tools http://www.anilcetin.com/ I find a way to get pwx working with nginx. So here's my nginx working configuration:

server {
    listen 80;
    server_name     pwx.example.com;

    access_log      /var/log/nginx/access-pwx.log;
    error_log       /var/log/nginx/error-pwx.log;

    root /var/www/pwx/web;
    index index.php;

    location ~* \.php$ {
        try_files $uri =404;
        include fastcgi.conf;
        fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
        fastcgi_index  index.php;
    }

    location / {
        if (!-f $request_filename){
            set $rule_0 1$rule_0;
        }
        if ($rule_0 = "1"){
            rewrite ^/ /index.php last;
        }
    }

    location ~ /\. {
        access_log off;
        log_not_found off;
        deny all;
    }

}

i know that for nginx "if is evil" but right now I don't find another solution to get pwx working.

MichaelThessel commented 8 years ago

Glad you figured this out. Have you had a look at the Silex documentation? I didn't modify the default .htaccess that shipped with Silex. I would assume their default nginx config should cover all the use cases too.

wilf1rst commented 8 years ago

Thanks for the link, that config works too. I haven't look at silex documentation because I don't know what to search, I don't even know silex before today :). By the way thanks for your tools it's very useful.

MichaelThessel commented 8 years ago

Sure thing, glad it works.