从 Apache 切换到 Nginx - 503 错误

从 Apache 切换到 Nginx - 503 错误

从 Apache 切换到 Nginx 导致了一些错误。我们的论坛图像无法加载,并且带有重定向等的目录实际上并没有重定向。

这两个问题是 /forum/uploads/avatars 和 /pack/。以下是配置。

server {
    listen 80;

    root /var/www;
    server_name craftblock.me;
    index index.php index.html index.htm;

    location / {
        try_files $uri $uri/ /index.php?q=$uri&$args;
        autoindex on;
        index  index.php index.html index.htm;
    }

    location ~ /forum/(inc|uploads/avatars) {
        allow all;
        try_files $uri;
        satisfy any;
    }

    location /forum {
        rewrite ^/forum/forum-([0-9]+)\.html$ /forum/forumdisplay.php?fid=$1;
        rewrite ^/forum/forum-([0-9]+)-page-([0-9]+)\.html$ /forum/forumdisplay.php?fid=$1&page=$2;
        rewrite ^/forum/thread-([0-9]+)\.html$ /forum/showthread.php?tid=$1;
        rewrite ^/forum/thread-([0-9]+)-page-([0-9]+)\.html$ /forum/showthread.php?tid=$1&page=$2;
        rewrite ^/forum/thread-([0-9]+)-lastpost\.html$ /forum/showthread.php?tid=$1&action=lastpost;
        rewrite ^/forum/thread-([0-9]+)-nextnewest\.html$ /forum/showthread.php?tid=$1&action=nextnewest;
        rewrite ^/forum/thread-([0-9]+)-nextoldest\.html$ /forum/showthread.php?tid=$1&action=nextoldest;
        rewrite ^/forum/thread-([0-9]+)-newpost\.html$ /forum/showthread.php?tid=$1&action=newpost;
        rewrite ^/forum/thread-([0-9]+)-post-([0-9]+)\.html$ /forum/showthread.php?tid=$1&pid=$2;

        rewrite ^/forum/post-([0-9]+)\.html$ /forum/showthread.php?pid=$1;

        rewrite ^/forum/announcement-([0-9]+)\.html$ /forum/announcements.php?aid=$1;

        rewrite ^/forum/user-([0-9]+)\.html$ /forum/member.php?action=profile&uid=$1;

        rewrite ^/forum/calendar-([0-9]+)\.html$ /forum/calendar.php?calendar=$1;
        rewrite ^/forum/calendar-([0-9]+)-year-([0-9]+)\.html$ /forum/calendar.php?action=yearview&calendar=$1&year=$2;
        rewrite ^/forum/calendar-([0-9]+)-year-([0-9]+)-month-([0-9]+)\.html$ /forum/calendar.php?calendar=$1&year=$2&month=$3;
        rewrite ^/forum/calendar-([0-9]+)-year-([0-9]+)-month-([0-9]+)-day-([0-9]+)\.html$ /forum/calendar.php?action=dayview&calendar=$1&year=$2&month=$3&day=$4;
        rewrite ^/forum/calendar-([0-9]+)-week-(n?[0-9]+)\.html$ /forum/calendar.php?action=weekview&calendar=$1&week=$2;

        rewrite ^/forum/event-([0-9]+)\.html$ /forum/calendar.php?action=event&eid=$1;

        # Google SEO workaround for search.php highlights:
        # Make this rule the first rewrite rule in your .htaccess!
        rewrite ^/MyBB/([^&]*)&(.*)$ http://yoursite/MyBB/$1?$2 permanent;

        # Google SEO Sitemap:
        rewrite ^/MyBB/((?i)sitemap-([^./]+)\.xml)$ /MyBB/misc.php?google_seo_sitemap=$2;

        # Google SEO URL Forums:
        rewrite ^/MyBB/((?i)Forum-([^./]+))$ /MyBB/forumdisplay.php?google_seo_forum=$2;

        # Google SEO URL Threads:
        rewrite ^/MyBB/((?i)Thread-([^./]+))$ /MyBB/showthread.php?google_seo_thread=$2;

        # Google SEO URL Announcements:
        rewrite ^/MyBB/((?i)Announcement-([^./]+))$ /MyBB/announcements.php?google_seo_announcement=$2;

        # Google SEO URL Users:
        rewrite ^/MyBB/((?i)User-([^./]+))$ /MyBB/member.php?action=profile&google_seo_user=$2;

        # Google SEO URL Calendars:
        rewrite ^/MyBB/((?i)Calendar-([^./]+))$ /MyBB/calendar.php?google_seo_calendar=$2;

        # Google SEO URL Events:
        rewrite ^/MyBB/((?i)Event-([^./]+))$ /MyBB/calendar.php?action=event&google_seo_event=$2;
    }

    location /nano/public {
        if (!-e $request_filename){
        rewrite ^(.*)$ /index.php/$1 break;
        }
        try_files $uri;
    }

    location ~ /index.php/ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }

    location /phpmyadmin {
        root /usr/share/;
        index index.php index.html index.htm;
        location ~ ^/phpmyadmin/(.+\.php)$ {
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            include fastcgi_params;
        }
        location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
            root /usr/share/;
        }
    }
    location /phpMyAdmin {
           rewrite ^/* /phpmyadmin last;
    }

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }

    location ~/\.ht {
        deny all;
    }

}

我做错了什么?想不通。

答案1

的问题location /pack/public在于重写目标不以 结尾.php。这意味着执行不会传递给 ,并且location ~ \.php$永远不会用于这些脚本。

如果您确实需要以样式调用 PHP 脚本/index.php/URL,则需要添加一个新的位置块,如下所示:

location ~ /index.php/ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
}

相关内容