1

我的服务器的适当 Nginx 配置有问题。

It 上部署的 php 应用程序是OJS,一个期刊管理和发布系统,最初开发用于在 Apache 1上运行。尽管 OJS 可以在没有进一步特定服务器配置的情况下在 Nginx 上运行,但必须对 OJS 主配置设置(disable_path_info ON)进行细微更改,因为 Nginx 似乎不支持 PATH_INFO。然而,这会生成非漂亮的 URL,这反过来会导致一些 OJS 功能/插件超出规范,或者根本无法工作2

我发现一些帖子是人们分享这方面的成功经验:

我在 Laravel Forge 配置的 Digital Ocean 帐户上运行 Ubuntu 18.04.1 LTS (GNU/Linux 4.15.0-42-generic x86_64)。

我找不到将这些代码块(上面链接示例中的代码块)与我的默认 Nginx 设置相结合的方法。

# FORGE CONFIG (DO NOT REMOVE!)
include forge-conf/evidenciaonojs.tk/before/*;

server {
    listen 80;
    listen [::]:80;
    server_name evidenciaonojs.tk;
    root /home/forge/evidenciaonojs.tk/;

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

    ssl_protocols TLSv1.2;
    ssl_ciphers ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384;
    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 (DO NOT REMOVE!)
    include forge-conf/evidenciaonojs.tk/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/evidenciaonojs.tk-error.log error;

    error_page 404 /index.php;

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

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

# FORGE CONFIG (DO NOT REMOVE!)
include forge-conf/evidenciaonojs.tk/after/*;

我希望将 OJS 配置文件改回 disable_path_info Off 并能够在 Nginx 上运行时使用漂亮的 URL。

对此的任何帮助将不胜感激!

4

2 回答 2

2

我刚刚在 OJS3 论坛上看到了您的消息。

对于 NginX 试试这个配置

# FORGE CONFIG (DO NOT REMOVE!)
include forge-conf/evidenciaonojs.tk/before/*;

server {
    listen 80;
    listen [::]:80;
    server_name evidenciaonojs.tk;
    root /home/forge/evidenciaonojs.tk/;

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

    ssl_protocols TLSv1.2;
    ssl_ciphers ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384;
    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 (DO NOT REMOVE!)
    include forge-conf/evidenciaonojs.tk/server/*;

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

    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/evidenciaonojs.tk-error.log error;

    error_page 404 /index.php;

    location ~ ^(.+\.php)(.*)$ {
        set $path_info $fastcgi_path_info;
        fastcgi_split_path_info ^(.+\.php)(.*)$;
        fastcgi_param PATH_INFO $path_info;
        fastcgi_param PATH_TRANSLATED $document_root$path_info;

        if (!-f $document_root$fastcgi_script_name) {
            return 404;
        }
        include fastcgi_params;

        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

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

# FORGE CONFIG (DO NOT REMOVE!)
include forge-conf/evidenciaonojs.tk/after/*;

请务必设置:
1.cgi.fix_pathinfo=1在 PHP-FPM 中(可能在 /etc/php/7.2/fpm/php.ini 中)。
2.security.limit_extensions = .php在您的 FPM 池配置文件中(在 /etc/php/7.2/fpm/pool.d/your_site.conf 中)
3. disable_path_info = Off(在 OJS config.inc.php 中)

重启 PHP-FPM 和 NginX 服务。然后,如果它有效,请阅读有关 NginX IF 和“cgi.fix_pathinfo”的弊端。

于 2019-01-19T22:41:02.753 回答
1

只需确认在我的案例中对在 Nginx 上成功运行 OJS 有用的东西(在 Laravel Forge 配置的 Digital Ocean 帐户上的 Ubuntu 18.04.1 LTS)包括:

1)修改PHP-FPM中的cgi.fix_pathinfo=1(在/etc/php/7.2/fpm/php.ini中)

2)取消注释(启用)security.limit_extensions = .php(在/etc/php/7.2/fpm/pool.d/www.conf中)

3) 更改 disable_path_info = Off(在 OJS config.inc.php 中)。

4) 将 nginx 配置替换为:

# FORGE CONFIG (DO NOT REMOVE!)
 include forge-conf/evidenciaonojs.tk/before/*;

 server {
     listen 80;
     listen [::]:80;
     server_name evidenciaonojs.tk;
     root /home/forge/evidenciaonojs.tk/;

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

 ssl_protocols TLSv1.2;
 ssl_ciphers ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384;
 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 (DO NOT REMOVE!)
 include forge-conf/evidenciaonojs.tk/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/evidenciaonojs.tk-error.log error;

 error_page 404 /index.php;

 location ~ ^(.+\.php)(.*)$ {
     set $path_info $fastcgi_path_info;
     fastcgi_split_path_info ^(.+\.php)(.*)$;
     fastcgi_param   PATH_INFO               $path_info;
     fastcgi_param   PATH_TRANSLATED         $document_root$path_info;
     fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
     fastcgi_index index.php;
     include fastcgi_params;
 }

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

 # FORGE CONFIG (DO NOT REMOVE!)
 include forge-conf/evidenciaonojs.tk/after/*;

5)最后重启服务(service php7.2-fpm restart AND sudo service nginx restart)。

于 2019-02-07T15:17:58.010 回答