Categories

See More
Popular Forum

MBA (4887) B.Tech (1769) Engineering (1486) Class 12 (1030) Study Abroad (1004) Computer Science and Engineering (988) Business Management Studies (865) BBA (846) Diploma (746) CAT (651) B.Com (648) B.Sc (643) JEE Mains (618) Mechanical Engineering (574) Exam (525) India (462) Career (452) All Time Q&A (439) Mass Communication (427) BCA (417) Science (384) Computers & IT (Non-Engg) (383) Medicine & Health Sciences (381) Hotel Management (373) Civil Engineering (353) MCA (349) Tuteehub Top Questions (348) Distance (340) Colleges in India (334)
See More

Nginx: Multiple PHP fpm on subdirectories in one domain

General Tech Bugs & Fixes

Max. 2000 characters
Replies

usr_profile.png

User

( 5 months ago )

 

I need to have multiple PHP-FPMs on single domain.

Example: services.local/notification -> notification:9000 services.local/auth -> auth:9000

So, I have a vhost configuration:

server {
    server_name services.local;
    root /www;

    include /etc/nginx/conf.d/services/*.conf;
    error_log /var/log/nginx/symfony_error.log;
}

And I have a notification.conf

location /notification {
    root /www/;
    index app.php index.html;

    #try_files $uri $uri /notification/web/app.php?$is_args$args;
    rewrite ^(.*)$ /notification/web/app.php last;
}


location /notification/web/app.php {
    fastcgi_pass notification-upstream;
    fastcgi_split_path_info ^(.+\.php)(/.*)$;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME /www/notification/web/app.php;
    fastcgi_param HTTPS on;
}

The problem is that every rewrite to the app.php results in downloading it's contents, not passing it to FPM.

When I access the app.php directly then it's passed to PHP-FPM, only problem is with a combination of subdirectory + PHP-FPM + rewrite

I think I tried everything for two days and I don't have any other ideas. This config was rebuilded 50 times :)

usr_profile.png

User

( 5 months ago )

Finally I found the solution. I don't know only if it would work with static assets, probably not, but this was not my case. Feel free to beautify and simplify this code as I'm aware that it looks a little bit ugly but it's working perfectly.

location ~ /notification {
    set $new_request_uri /;
    if ($request_uri ~ ^/notification(.+)$) {
        set $new_request_uri $1;
    }

    if ($request_uri ~ ^/notification\?(.+)$) {
        set $new_request_uri /?$1;
    }

    set $new_document_uri /;
    if ($document_uri ~ ^/notification(.+)$) {
        set $new_document_uri $1;
    }

    fastcgi_pass wolnosciowiec_notification:9000;
    fastcgi_split_path_info ^(.+\.php)(/.*)$;
    include fastcgi_params;
    fastcgi_param REQUEST_URI     $new_request_uri;
    fastcgi_param DOCUMENT_URI    $new_document_uri;
    fastcgi_param SCRIPT_NAME     /www/notification/web/app.php;
    fastcgi_param SCRIPT_FILENAME /www/notification/web/app.php;
    fastcgi_param DOCUMENT_ROOT   /www/notification/web;
    fastcgi_param HTTPS on;
}

what's your interest


forum_ban8_5d8c5fd7cf6f7.gif