尝试在我的 CentOS 7 VPS 上使用 Nginx 安装 phpBB (3.2.7) 并收到 403、502 错误或默认页面

尝试在我的 CentOS 7 VPS 上使用 Nginx 安装 phpBB (3.2.7) 并收到 403、502 错误或默认页面

我正在尝试使用 Nginx 在我的 CentOS 7 VPS 上安装 phpBB (3.2.7),但我不断交替收到这些错误:

  • 403 - 禁止访问
  • Nginx 默认页面显示 Web 服务器正在运行,但尝试访问时出现 404 http://1.2.3.4/install(安装 phpBB 所需)
  • 502错误的网关(目前困境)

以下是我的/etc/nginx/nginx.cfg

user    nginx nginx;

events {
    worker_connections  1024;
}

http {
    include     /etc/nginx/mime.types;

    # Compression - requires gzip and gzip static modules.
    gzip on;
    gzip_static on;
    gzip_vary on;
    gzip_http_version 1.1;
    gzip_min_length 700;

    # Compression levels over 6 do not give an appreciable improvement
    # in compression ratio, but take more resources.
    gzip_comp_level 6;

    # IE 6 and lower do not support gzip with Vary correctly.
    gzip_disable "msie6";
    # Before nginx 0.7.63:
    #gzip_disable "MSIE [1-6]\.";

    # Catch-all server for requests to invalid hosts.
    # Also catches vulnerability scanners probing IP addresses.
    server {
        # default specifies that this block is to be used when
        # no other block matches.
        listen 80 default;

        server_name bogus;
        return 444;
        root /var/empty;
    }

    # NOTE: uncommenting this section causes the program to print to console: 
    #'nginx: [warn] conflicting server name "1.2.3.4" on 0.0.0.0:80, ignored'
    # Typing in my VPS IP results in 414 - URI Too Large 
    # http://1.2.3.4/1.2.3.4/1.2.3.4/1.2.3.4 ...

    # If you have domains with and without www prefix,
    # redirect one to the other.
    #server {
    #    # Default port is 80.
    #    listen 80;
    #    server_name 1.2.3.4;
         # A trick from http://wiki.nginx.org/Pitfalls#Taxing_Rewrites:
    #    return 301 1.2.3.4$request_uri;
    #}

    # The actual board domain.
    server {
        listen [::]:80;
        listen 80;
        server_name 1.2.3.4;
        root /var/www/html/mydomain.com/phpBB-3.2.7;

        location / {
            # phpBB uses index.htm
            index index.php index.html index.htm;
            try_files $uri $uri/ @rewriteapp;
        }

        location @rewriteapp {
            rewrite ^(.*)$ /app.php/$1 last;
        }

        # Deny access to internal phpbb files.
        location ~ /(config\.php|common\.php|cache|files|images/avatars/upload|includes|(?<!ext/)phpbb|store|vendor) {
            deny all;
            # deny was ignored before 0.8.40 for connections over IPv6.
            # Use internal directive to prohibit access on older versions.
            internal;
        }

        # Pass the php scripts to fastcgi server specified in upstream declaration.
        location ~ \.php(/|$) {
            # Unmodified fastcgi_params from nginx distribution.
            include fastcgi_params;
            # Necessary for php.
            fastcgi_split_path_info ^(.+\.php)(/.*)$;
            fastcgi_param PATH_INFO $fastcgi_path_info;
            fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
            fastcgi_param DOCUMENT_ROOT $realpath_root;
            try_files $uri $uri/ /app.php$is_args$args;
            fastcgi_pass php;
        }

        # Correctly pass scripts for installer
        location /install/ {
            # phpBB uses index.htm
            try_files $uri $uri/ @rewrite_installapp;

            # Pass the php scripts to fastcgi server specified in upstream declaration.
            location ~ \.php(/|$) {
                # Unmodified fastcgi_params from nginx distribution.
                include fastcgi_params;
                # Necessary for php.
                fastcgi_split_path_info ^(.+\.php)(/.*)$;
                fastcgi_param PATH_INFO $fastcgi_path_info;
                fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
                fastcgi_param DOCUMENT_ROOT $realpath_root;
                try_files $uri $uri/ /install/app.php$is_args$args;
                fastcgi_pass php;
            }
        }

        location @rewrite_installapp {
            rewrite ^(.*)$ /install/app.php/$1 last;
        }

        # Deny access to version control system directories.
        location ~ /\.svn|/\.git {
            deny all;
            internal;
        }
    }

    # If running php as fastcgi, specify php upstream.
    upstream php {
        server 127.0.0.1:9000;
    }
}

其他信息:

  • 更改了以下几行/etc/php.ini

    max_execution_time = 180
    max_input_time = 60
    memory_limit = 256M
    upload_max_filesize = 64M
    
  • 我使用静态 IP 是因为我正在等待我的域名从之前的托管公司转移。我假设我可以将 VPS 的静态 IP(例如 1.2.3.4)放置在实际域名的位置,并在转移后将其替换为域名?

答案1

所以我修复了它,不确定到底是什么起了作用,但取消注释上面的注释块是一个昂贵的这次绕行给我们上了宝贵的一课,让我们知道要相信自己先前的判断。

/etc/nginx/nginx.cfg

user        nginx nginx;
error_log   /var/log/nginx.error_log info;  # [ debug | info | notice | warn | error | crit ]

events {
    worker_connections   4096;
}

http {
    include     mime.types;
    include     /etc/nginx/sites_enabled/*.conf;
    server_names_hash_bucket_size 64;

    # Compression - requires gzip and gzip static modules.
    gzip on;
    gzip_static on;
    gzip_vary on;
    gzip_http_version 1.1;
    gzip_min_length 700;

    # Compression levels over 6 do not give an appreciable improvement
    # in compression ratio, but take more resources.
    gzip_comp_level 6;

    # IE 6 and lower do not support gzip with Vary correctly.
    gzip_disable "msie6";
    # Before nginx 0.7.63:
    #gzip_disable "MSIE [1-6]\.";

    # Catch-all server for requests to invalid hosts.
    # Also catches vulnerability scanners probing IP addresses.
    server {
        # default specifies that this block is to be used when
        # no other block matches.
        listen         80 default_server;
        listen         [::]:80 default_server;

        server_name bogus;
        return 444;
        root /var/empty;
    }

    # If running php as fastcgi, specify php upstream.
    upstream php {
        server 127.0.0.1:9000;
    }
}

/etc/nginx/sites_available/exampledomain.com.conf

server {
    listen          80;
    server_name     exampledomain.com www.exampledomain.com;
    root            /var/www/html/exampledomain.com/phpBB-3.2.7;

    location / {
        # phpBB uses index.htm
        index index.php index.html index.htm;
        try_files $uri $uri/ @rewriteapp;
    }

    location @rewriteapp {
        rewrite ^(.*)$ /app.php/$1 last;
    }

    # Deny access to internal phpbb files.
    location ~ /(config\.php|common\.php|cache|files|images/avatars/upload|includes|(?<!ext/)phpbb|store|vendor) {
        deny all;
        # deny was ignored before 0.8.40 for connections over IPv6.
        # Use internal directive to prohibit access on older versions.
        internal;
    }

    # Pass the php scripts to fastcgi server specified in upstream declaration.
    location ~ \.php(/|$) {
        # Unmodified fastcgi_params from nginx distribution
        include fastcgi_params;

        # Necessary for php
        fastcgi_split_path_info  ^(.+\.php)(/.*)$;
        fastcgi_param   PATH_INFO $fastcgi_path_info;
        fastcgi_param   SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        fastcgi_param   DOCUMENT_ROOT $realpath_root;
        try_files   $uri $uri/ /app.php$is_args$args;
        fastcgi_pass    php;
    }

    # Correctly pass scripts for installer
    location /install/ {
        # phpBB uses index.htm
        try_files $uri $uri/ @rewrite_installapp;

        # Pass the php scripts to fastcgi server specified in upstream declaration.
        location ~ \.php(/|$) {
            # Unmodified fastcgi_params from nginx distribution.
            include fastcgi_params;

            # Necessary for php.
            fastcgi_split_path_info     ^(.+\.php)(/.*)$;
            fastcgi_param PATH_INFO     $fastcgi_path_info;
            fastcgi_param SCRIPT_FILENAME   $realpath_root$fastcgi_script_name;
            fastcgi_param DOCUMENT_ROOT $realpath_root;

            try_files $uri $uri/ /install/app.php$is_args$args;
            fastcgi_pass php;
        }
    }

    location @rewrite_installapp {
        rewrite ^(.*)$ /install/app.php/$1 last;
    }

    # Deny access to version control system directories.
    location ~ /\.svn|/\.git {
        deny all;
        internal;
    }
}

需要注意以下几点:

  • 为了避免以后出现麻烦,我将服务器块移出 /etc/nginx/nginx.conf到一个单独的文件中,/etc/nginx/sites_available并使用符号链接指向/etc/nginx/sites_enabled
  • IPv4 地址已被 exampledomain.com 取代。这是因为我的域名在 OP 和此答案之间转移了,所以我不再需要使用该 IP。
  • 必须降级到 PHP 7.2 才能使用 phpBB;在尝试了几个指南均未成功后,我通过本指南实现了此目标这里

相关内容