【问题标题】:nginx config for phpbb and laravelphpbb 和 laravel 的 nginx 配置
【发布时间】:2017-09-14 22:41:54
【问题描述】:

我需要一个适用于 Laravel 和 Phpbb 的 nginx 配置。

我使用 laravel forge 设置了我的数字海洋服务器,它创建了这个 nginx 配置:

# FORGE CONFIG (DOT NOT REMOVE!)
include forge-conf/djembefola.org/before/*;

server {
    listen 80;
    listen [::]:80;
    server_name djembefola.org;
    root /home/forge/djembefola.org/public;

    # FORGE SSL (DO NOT REMOVE!)
    # ssl_certificate;
    # ssl_certificate_key;

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:$
    ssl_prefer_server_ciphers on;
    ssl_dhparam /etc/nginx/dhparams.pem;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    index index.html index.htm index.php;

    charset utf-8;

    # FORGE CONFIG (DOT NOT REMOVE!)
    include forge-conf/djembefola.org/server/*;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    access_log off;
    error_log  /var/log/nginx/djembefola.org-error.log error;

    error_page 404 /index.php;

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

    location ~ /\.(?!well-known).* {
        deny all;
    }
}

# FORGE CONFIG (DOT NOT REMOVE!)
include forge-conf/djembefola.org/after/*;

/public 文件夹是 Laravel 的前端控制器 index.php 所在的文件夹...

同样在公共文件夹中,我有并安装了 phpbb - /公共/董事会

我正在升级论坛,因此我需要安装 phpbb 安装程序,它位于:

本地主机/板/安装,

然后调用:

localhost/board/install/app.php/update

上面的 url 然后给出 404 错误。

我在其他地方读到这是因为 Nginx 需要正确配置才能运行安装程序。

示例 Nginx 配置 for phpbb is listed here.

所以我需要以某种方式合并这些,但到目前为止我的尝试都失败了。

我尝试添加:

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

到现有的 laravel nginx 文件,但是失败了。我知道我需要将它放在 nginx 配置中的正确位置,但我担心我可能忽略了其他东西,因为我在这里猜测了一下......

有人可以帮忙吗?

【问题讨论】:

    标签: laravel nginx phpbb


    【解决方案1】:

    根据示例配置,您可以将所需的规则嵌套在块包装中(就像它们对 /install/ 目录所做的那样)。例如:

    location /board/ {
        try_files $uri $uri/ @rewriteapp;    
    
        # 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/ /board/app.php$is_args$args;
            fastcgi_pass php;
        }
    }
    
    location @rewriteapp {
        rewrite ^(.*)$ /app.php/$1 last;
    }
    

    请注意,@rewriteapp 在块包装之外。如果你试图把它放在里面,Nginx 会报错。

    只需修改路径以匹配您的目录。

    【讨论】:

      猜你喜欢
      • 2016-09-24
      • 2017-07-25
      • 2014-02-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-27
      • 1970-01-01
      • 1970-01-01
      • 2015-01-05
      相关资源
      最近更新 更多