nginx - php fastgi - 用户目录

nginx - php fastgi - 用户目录

我有一个这样的配置:

worker_processes  2;  
error_log  logs/error.log;
pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;
    server_names_hash_bucket_size 64; 

    access_log  logs/access.log;

    sendfile        on; 
    tcp_nopush     on; 
    tcp_nodelay    on; 

    keepalive_timeout  75 20; 

    gzip  on; 
    gzip_comp_level 1;

    gzip_proxied any;
    gzip_min_length 1100;
    gzip_buffers 4 8k;
    gzip_types text/plain text/css application/x-javascript text/xml application/xml    application/xml+rss text/javascript;

    server {
        listen       80;
        server_name  localhost;
        access_log  logs/host.access.log;

        location / {
            root   /var/www;
            index  index.html index.htm;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /var/www;
        }
        location ~* ^.+\.(jpg|jpeg|gif)$ {
            root         /var/www;
            access_log   off;
            expires      30d;
        }

        location ~ /\.ht {
            deny  all;
        }

        location ~ ^/~(.+?)(/.*)?$ {
            alias /home/$1/public_html$2;
            index  index.html index.htm;
            autoindex on;
            location ~ \.php$ {
                    root /home/$1/public_html;
                    include php_fastcgi.conf;
                    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            }
        }
        location ~ \.php$ {
            root           /var/www;
            include php_fastcgi.conf;
            fastcgi_param  SCRIPT_FILENAME  /var/www$fastcgi_script_name;
        }
}

其中,php_fastcgi.conf文件的内容如下:

fastcgi_pass   127.0.0.1:9000;
fastcgi_index  index.php;
include        fastcgi_params;
fastcgi_connect_timeout 60; 
fastcgi_send_timeout 180;
fastcgi_read_timeout 180;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
fastcgi_intercept_errors on;

如果我尝试调用 mydomain.org/index.php 之类的页面,一切顺利,但是,当我尝试打开用户位置的页面(mydomain/~user/index.php)时,我收到此错误:“未指定输入文件。” 有办法解决这个问题吗?

答案1

我找到了解决方案。这个新的 conf 文件有效。

worker_processes  2;  
error_log  logs/error.log;
pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;
    server_names_hash_bucket_size 64; 

    access_log  logs/access.log;

    sendfile        on; 
    tcp_nopush     on; 
    tcp_nodelay    on; 

    keepalive_timeout  75 20; 

    gzip  on; 
    gzip_comp_level 1;

    gzip_proxied any;
    gzip_min_length 1100;
    gzip_buffers 4 8k;
    gzip_types text/plain text/css application/x-javascript text/xml application/xml    application/xml+rss text/javascript;

    server {
        listen       80;
        server_name  localhost;
        access_log  logs/host.access.log;

        location / {
            root   /var/www;
            index  index.html index.htm;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /var/www;
        }
        location ~* ^.+\.(jpg|jpeg|gif)$ {
            root         /var/www;
            access_log   off;
            expires      30d;
        }

        location ~ /\.ht {
            deny  all;
        }
        location ~ ^/~(.+?)(/.*\.php)?$ {
                root /home/$1/public_html;
                include php_fastcgi.conf;
                fastcgi_param SCRIPT_FILENAME /home/$1/public_html$2;
        }
        location ~ ^/~(.+?)(/.*)?$ {
            alias /home/$1/public_html$2;
            index  index.html index.htm;
            autoindex on;
        }
        location ~ \.php$ {
            root           /var/www;
            include php_fastcgi.conf;
            fastcgi_param  SCRIPT_FILENAME  /var/www$fastcgi_script_name;
        }
}

答案2

nginx.conf尝试从此处更新文件的以下部分:

location ~ \.php$ {
    root           /var/www;
    include php_fastcgi.conf;
    fastcgi_param  SCRIPT_FILENAME  /var/www$fastcgi_script_name;
}

...变成这样:

location ~ \.php$ {
    root           /var/www*;
    fastcgi_pass    127.0.0.1:9000;
    fastcgi_index   index.php;
    fastcgi_param   SCRIPT_FILENAME /var/www/$fastcgi_script_name;
    include         fastcgi_params;
}

另外,请确保在进行更改后重新启动 nginx。

相关内容