nginx + PHP-fpm 配置示例

itxq發表於2019-12-19

Nginx 配置檔案示例

server
{
        # nginx
        listen 80;
        listen [::]:80;
        server_name _;
        server_name_in_redirect off;
        index   index.php index.html index.htm default.php default.htm default.html;
        root    /www/public;

        # rewrite
        location /
        {
                if (!-e $request_filename){
                        rewrite ^(.*)$ /index.php$1 last;
                }
        }

        # php
        location ~ \.php(.*)$
        {
                fastcgi_pass 127.0.0.1:9000;
                fastcgi_index index.php;
                set $real_script_name $fastcgi_script_name;
                if ($fastcgi_script_name ~ "^(.+?\.php)(.+)$") {
                        set $real_script_name $1;
                        set $path_info $2;
                 }
                fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
                fastcgi_param SCRIPT_NAME $real_script_name;
                fastcgi_param PATH_INFO $path_info;
                fastcgi_param  PHP_VALUE  "open_basedir=/www/:/tmp/:/proc/";
                include fastcgi_params;
        }

        # image
        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires      30d;
            error_log off;
            access_log /dev/null;
        }

        # js & css
        location ~ .*\.(js|css)?$
        {
            expires      12h;
            error_log off;
            access_log /dev/null; 
        }

        # log
        access_log  /www/wwwlogs/default.log;
        error_log  /www/wwwlogs/default.error.log;
}

PHP 配置檔案示例

# 禁用函式
disable_functions = passthru,exec,system,chroot,chgrp,chown,shell_exec,popen,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
# 開啟 pathinfo
cgi.fix_pathinfo=1
本作品採用《CC 協議》,轉載必須註明作者和本文連結

這不是一個 BUG,這只是一個未列出來的特性!

相關文章