0

I have a Wordpress installation, and in it's root folder I have a custom built external service. This external service I would like to run on a separate pool. So I created 2 pools of php FPM for it one will be running in 127.0.0.1:9000 and the second is in: 127.0.0.1:9001

I checked that I can telnet to this port and that it's open and working.

My NGINX would not send the data in. Here is my nginx configuration:

server {
    listen 80;

    root /var/www/website;
    index index.php index.html index.htm;

    location / {
            # try_files $uri $uri/ =404;
            try_files $uri $uri/ /index.php?q=$uri&$args;
    }

    error_page 404 /404.html;

    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
            root /usr/share/nginx/html;
    }

    location /service {
    #       include cors;
            try_files $uri =404;
            fastcgi_param REMOTE_ADDR $http_x_real_ip;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass 127.0.0.1:9001;
            fastcgi_index index.php;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
            fastcgi_param REMOTE_ADDR $http_cf_connecting_ip;

    }

    location ~ \.php$ {
            try_files $uri =404;
            fastcgi_param REMOTE_ADDR $http_x_real_ip;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
            fastcgi_param REMOTE_ADDR $http_cf_connecting_ip;

    }
}

Now when I go to

http://localhost/service

I am getting 404 of the wordpress, but when I go to

http://localhost/service/index.php

I am getting the service.

If I remove the

location /service

from the Nginx configuration I am getting the index.php in the service folder when I am navigating to http://localhost/service

How do I configure things so the service is called on the /service URL?

Alex Frenkel
  • 111
  • 1
  • 6
  • I've cleaned up your formatting, please check to ensure it's done correctly. Please ensure your question is precise, especially the last couple of sentences. Have a read of this : http://nginx.org/en/docs/http/request_processing.htm . I'd try adding a slash to the end of the location /service/ just to see what happens. – Tim Feb 03 '17 at 04:31
  • Thanks, Since I am not allowed links I had to remove them all from the text. – Alex Frenkel Feb 03 '17 at 11:17
  • I had tried to add slash, to remove slash, to add and ~ before, nothing... – Alex Frenkel Feb 03 '17 at 11:18
  • Please edit your question, it's imprecise. You've created two pool, but of what - PHP? Two location blocks? What does "Nginx would not send the data in" mean? Have you tried adding headers to check which location block is being used, then looking at response using curl -k or similar? – Tim Feb 03 '17 at 18:19
  • @Tim - Thanks for the comment, I have changed the question, it's php-fpm pools. I am not at work already but I have not though about adding a custom header to check what location was activated! Thank you! – Alex Frenkel Feb 03 '17 at 22:05
  • @Tim have checked using the headers like you say, I have added add_header X-my-header my-header-content; and add_header X-my-header1 my-header-content; and can see that it's not entering it at all.... :( – Alex Frenkel Feb 07 '17 at 11:58
  • Read this article and experiment, using headers to determine what's happening : https://www.digitalocean.com/community/tutorials/understanding-nginx-server-and-location-block-selection-algorithms – Tim Feb 07 '17 at 18:11

1 Answers1

0

Nginx config is executed sequentially, so in order to have it stop after the first match you'll need to add the break directive like this:

location /service {
#       include cors;
        try_files $uri =404;
        fastcgi_param REMOTE_ADDR $http_x_real_ip;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass 127.0.0.1:9001;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
        fastcgi_param REMOTE_ADDR $http_cf_connecting_ip;
        break;

}
Anubioz
  • 3,677
  • 18
  • 23