I need to configure Nginx with two sites that run different versions of php in the same ip

0

Sorry for the inconvenience, I have a laravel application working correctly, and another billing system in an old php that I need to place in an Amazon EC2, and I have difficulties to configure the nginx, they are php of different versions in the same public ip of EC2

Server{
 listen 80 default_server;
 server_name _;

 location / {
  root /var/www/fac;
  include snippets/fastcgi-php.conf;
  fastcgi_pass unix:/run/php/php5.6-fpm.sock;
 } 

 location /prod {
  root /var/www/som/public;
  include snippets/fastcgi-php.conf;
  fastcgi_pass unix:/run/php/php7.1-fpm.sock;
 }
}

It is worth noting that I have already investigated, and I am asking for help because I have not managed to make it work correctly for both of them.

    
asked by Yalian 03.07.2018 в 18:57
source

1 answer

0

I see the syntax of .conf a bit strange, but the main thing is to put the matching rules in order and nest the location so that only the .php pass through the fastcgi.

Here is an example of .conf running with php 7.1 in / and php 5.6 in /v5

server {
        listen 80 default_server;
        listen [::]:80 default_server;

        root /var/www/html;

        index index.php index.html index.htm index.nginx-debian.html;

        server_name _;

        location / {
                try_files $uri $uri/ =404;
        }


    location /v5 {
      location  ~ \.php$ {
          try_files $uri =404;
          fastcgi_split_path_info ^(.+\.php)(/.+)$;
          # fastcgi_pass 127.0.0.1:9001;
          fastcgi_pass unix:/run/php/php5.6-fpm.sock;
          fastcgi_index index.php;
          include fastcgi_params;
          fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
          fastcgi_param PATH_INFO $fastcgi_path_info;
      }
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        # fastcgi_pass 127.0.0.1:9000;
        fastcgi_pass unix:/run/php/php7.1-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }

    location ~ /\.ht {
           deny all;
    }
}

Note: You may have to configure user and group to use the unix socket, the default installation is usually apache or www-data , in some configurations you will have to change it to nginx , First try the .conf as it is and then see the permissions.

Note 2: commented on how to use IP:puerto if you use this option you have to specify it in the listen of each fpm and have different ports

$ sudo nano /etc/php/5.6/fpm/pool.d/www.conf

; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
;       will be used.
user = nginx
group = nginx 

;   '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
listen = /run/php/php5.6-fpm.sock

$ sudo nano /etc/php/7.1/fpm/pool.d/www.conf

; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
;       will be used.
user = nginx
group = nginx 

;   '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
listen = /run/php/php7.1-fpm.sock
    
answered by 04.07.2018 / 04:12
source