статья от сюда
sudo pacman -S fcgi php-cgi
To avoid constantly running FastCGI from the console, let's create a script to launch the FastCGI daemon
sudo 'ваш любимый текстовый редактор' /etc/rc.d/php-cgi
and insert the following code into it
#!/bin/bash . /etc/rc.conf . /etc/rc.d/functions case "$1" in start) stat_busy 'Starting Fastcgi Server' if /usr/bin/php-cgi -b 127.0.0.1:9000 & then add_daemon fastcgi stat_done else stat_fail fi ;; stop) stat_busy 'Stopping Fastcgi Server' [ -e /var/run/daemons/fastcgi ] && kill $(pidof php-cgi) &> /dev/null; if [ $? -gt 0 ]; then stat_fail else rm_daemon fastcgi stat_done fi ;; restart) $0 stop $0 start ;;
*)
echo "Usage: $0 {start|stop|restart}"
esac
Save and exit. Now you can run FCGI as a daemon.
sudo /etc/rc.d/php-cgi start|stop|restart
From this code, it is clear that the FastCGI server will listen on 127.0.0.1 at port 9000. Therefore, configure nginx to proxy all requests for scripts there, in general, everything except static files. Open the nginx configuration file and make approximately the following changes: Depending on where your scripts are located, the location directives will differ. I will show an example for location /forum {
}
location /forum {
limit_conn one 10;
limit_rate_after 1m;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
root /srv/http/;
index index.html index.htm index.php;
location ~ \.php$ {
root /srv/http/forum;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /srv/http$fastcgi_script_name;
fastcgi_param QUERY_STRING $query_string;
fastcgi_buffers 8 16K;
include fastcgi_params;
}
In the location directive, you need to specify the entry point relative to external access, so to speak. That is, if the URL of your site is syslinux.ru, the corresponding location will be
location / { root /srv/http;
Similarly, for the request syslinux.ru/forum, it would look like this:
location /forum { root /srv/http;
In other words, by specifying different locations in the configuration, we control the locations and can create individual settings for each of them. Probably, the above part of the configuration can be written more concisely, but I currently lack the knowledge to do so. The key points of this configuration are:
location /forum {
Specifies the URL which, when accessed, will trigger the following rule.
root /srv/http/;
Here, the mapping between the URL and the file system is specified. In other words, the absolute path to the files that need to be served by nginx when accessing the root directory of the site is set. (syslinux.ru)
index index.html index.htm index.php;
Specifies the MIME type of index files; if they are missing, the page will not open even if it contains any other files different from the specified ones.
location ~ \.php$ {
Indicates that all .php scripts from the root /srv/http/forum below will be proxied to FastCGI, whose settings are provided below.
fastcgi_pass 127.0.0.1:9000;
This is actually the line that specifies where to proxy .php requests when accessing syslinux.ru/forum. In our case, this is FastCGI (in the daemon settings, we specified 127.0.0.1:9000). To proxy to Apache, you need to configure Apache to listen on port 8080 and write
proxy_pass http://127.0.0.1:8080;
And then all requests coming to /forum will be handled by Apache.
fastcgi_param SCRIPT_FILENAME /srv/http$fastcgi_script_name;
I didn't quite figure it out, but as I understood it, it points to the script. It works for me like this. By the way, regarding index files. I searched for a long time for how to enable directory listing when there is no index.php, *html, etc. in the directory. It turned out to be very simple, everything was in the nginx documentation, but since it was not possible to read it all at once, I googled for an analog of Apache's +Indexes. In the location directive for the target directory, you just need to add
autoindex on;
After all these maneuvers, you can restart nginx and start php-cgi
sudo /etc/rc.d/nginx restart
sudo /etc/rc.d/php-cgi start
Open your localhost in a browser and check if the scripts are running. Working? Great!
Now about awstats.
Everything I described above I set up quite quickly, but it took me a long time to get awstats working via fcgi. For a couple of days, Apache existed purely to display visit statistics :) So for this we will need fcgiwrap from AUR and spawn-fcgi from there as well. Build them, install them, and open the script to start the fcgi-wrap daemon
sudo 'ваш любимый текстовый редактор' /etc/conf.d/fcgiwrap
Edit it, specifying the user and group from which the script will be launched. (The user is the same one from which the nginx worker process runs, the group can be nobody or the same as the nginx user) specify the IP and port to listen on:
# Address and port to bind to ADDRESS="127.0.0.1" PORT="9001"
After that, go into the nginx config and insert this: (this is the only way it worked for me)
location /awstats {
root /srv/http/awstats/cgi-bin;
fastcgi_pass localhost:9001;
fastcgi_index index.php;
fastcgi_param SCRIPT_NAME /awstats.pl;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
include fastcgi_params;
allow 127.0.0.1; deny all;
}
Since the link to generate the awstats report looks like this: http://localhost/awstats/awstats.pl?config=syslinux.ru, specify
location /awstats {
root /path/to/yourserverroot/awstats/cgi-bin;
Specify the directory where the log analyzer script itself (awstats.pl) is located
fastcgi_pass localhost:9001;
Analogy - Specify where to proxy the request, in this case, to our FastCGI server.
fastcgi_param SCRIPT_NAME /awstats.pl;
Specify the script name, as I understood, it is taken relative to root (srv/http/awstats/cgi-bin). When specifying it in another way, I always got a 404 or 403 error, or "input file not specified"
allow 127.0.0.1; deny all;
