What is the difference between these two configuration methods of Nginx?
曾经蜡笔没有小新
曾经蜡笔没有小新 2017-05-16 17:24:22
0
1
504

Use $_GET[‘_url’] as source of URIs:

server {

    listen   80;
    server_name localhost.dev;

    index index.php index.html index.htm;
    set $root_path '/var/www/phalcon/public';
    root $root_path;

    try_files $uri $uri/ @rewrite;

    location @rewrite {
        rewrite ^/(.*)$ /index.php?_url=/;
    }

    location ~ \.php {
        fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
        fastcgi_index /index.php;

        include /etc/nginx/fastcgi_params;

        fastcgi_split_path_info       ^(.+\.php)(/.+)$;
        fastcgi_param PATH_INFO       $fastcgi_path_info;
        fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

    location ~* ^/(css|img|js|flv|swf|download)/(.+)$ {
        root $root_path;
    }

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

Use $_SERVER[‘REQUEST_URI’] as source of URIs:

server {

    listen   80;
    server_name localhost.dev;

    index index.php index.html index.htm;
    set $root_path '/var/www/phalcon/public';
    root $root_path;

    location / {
        try_files $uri $uri/ /index.php;
    }

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

    location ~* ^/(css|img|js|flv|swf|download)/(.+)$ {
        root $root_path;
    }

    location ~ /\.ht {
        deny all;
    }
}
曾经蜡笔没有小新
曾经蜡笔没有小新

reply all(1)
过去多啦不再A梦

The main difference between the two should be fastcgi_pass:

The second configuration is:

fastcgi_pass 127.0.0.1:9000;

The first configuration is:

fastcgi_pass unix:/run/php-fpm/php-fpm.sock;

Reference Wiki: http://zh.wikipedia.org/wiki/Unix_domain_socket

Unix domain socket or IPC socket is a terminal that enables data communication between two or more processes on the same operating system. Compared with pipes, Unix domain sockets can use both byte streams and data queues, while pipe communication can only use byte streams. The interface of Unix domain sockets is very similar to Internet sockets, but it does not use the underlying network protocol to communicate. The function of Unix domain socket is a component in the POSIX operating system.

Unix domain sockets use the address of the system file as their identity. It can be referenced by system processes. So two processes can open a Unix domain sockets at the same time to communicate. However, this communication method occurs in the system kernel and does not propagate in the network.

One conclusion is: When the server pressure is not high, there is not much difference between tcp and socket, but when the pressure is relatively high, the socket method is indeed better.

For details, please refer to this comparison to use socket to connect Nginx to optimize php-fpm performance

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!