Nginx differences when compiled manually

0

Good morning, You see I'm used to installing Nginx automatically ( apt-get install nginx ), but this time I had to compile it and configure it from its source, to add a module that does not come by default, and I found which is different from the normal structure for example I do not have " sites-available " and " sites-enabled ", how can I build an app with php-fpm without modifying the " nginx.conf "? in the normal procedure if you do it in " sites-available ".

    
asked by gburu98 30.08.2017 в 22:07
source

1 answer

0

The folder structure that NGINX has should not be a real problem, since the nginx process raises this based on its configuration file nginx.conf .

Normally an NGINX installation from the official repositories generates a structure like this:

etc
 |
 +-> nginx
       |
       +--> conf.d/
       |
       +--> modules-available/
       |
       +--> modules-enabled/
       |
       +--> sites-available/
       |
       +--> sites-enabled/
       |
       +--> snippets/

For purposes of answering what interests us are the nginx.conf file and the sites-enabled and sites-available folders, I explain below the purpose of these folders:

sites-available: Contains the virtual host that nginx by default brings, this virtual by generating it with the name default but you can Create much more virtual host according to the requirements. The fact that this in this folder does not mean that they are "published" by nginx.

sites-ebanled: Contains the direct links of the virtual hosts created in the sites-available folder, this is where nginx actually takes which virtual host publishes and which does not.

For your case, you can manually create these folders and add the following settings in your nginx.conf

...
http {
    ...
    include /etc/nginx/sites-enabled/*;
    ...
}

Now, if you do not want to have all these folders, just add the nginx configuration needed to process PHP files in the nginx.conf, it can be as follows:

http {
    ...
    location ~ \.php$ {
            # regex to split $uri to $fastcgi_script_name and $fastcgi_path
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            try_files $fastcgi_script_name =404;
            set $path_info $fastcgi_path_info;
            fastcgi_param PATH_INFO $path_info;
            fastcgi_index index.php; 
            include fastcgi.conf;

    #       # With php-fpm (or other unix sockets):
    #       fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
    #       # With php-cgi (or other tcp sockets):
    #       fastcgi_pass 127.0.0.1:9000;
    }
    ...
}

I have commented on the configuration of the fastcgi_pass and here it depends how you want to configure how nginx sends to process the PHP. The configuration I show is based on version 1.12.1 of NGINX

    
answered by 15.10.2017 в 01:18