我无法正确配置服务器的Nginx配置。
在It上部署的php应用为OJS,这是一种日记管理和发布系统,最初开发为在Apache 1上运行。 尽管OJS可以在没有其他特定服务器配置的情况下在Nginx上运行,但是由于PATH_INFO似乎不受Nginx支持,因此必须对OJS主配置设置进行较小的更改(disable_path_info ON)。但是,这些生成的URL不太漂亮,从而导致某些OJS功能/插件无法正常工作,或者根本无法工作2。
我发现一些帖子是人们分享成功经验的
我正在运行Ubuntu 18.04.1 LTS(GNU / Linux 4.15.0-42-通用x86_64) 在Laravel Forge配置的Digital Ocean帐户上。
我找不到将这段代码块(上面链接中示例中的代码块)与我的默认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关,并能够在Nginx上运行时使用漂亮的URL。
对此将提供任何帮助!
答案 0 :(得分:0)
我刚刚在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. {-{1}}在PHP-FPM中(可能在/etc/php/7.2/fpm/php.ini中)。
2. cgi.fix_pathinfo=1
在FPM池配置文件中(在/etc/php/7.2/fpm/pool.d/your_site.conf中)
3. security.limit_extensions = .php
(在OJS config.inc.php中)
重新启动PHP-FPM和NginX服务。然后,如果可行,请阅读有关NginX IF和'cgi.fix_pathinfo'的弊端。
答案 1 :(得分:0)
只需确认在我的案例中对在Nginx上成功运行OJS(在Laravel Forge配置的Digital Ocean帐户上的Ubuntu 18.04.1 LTS)有用的事情包括:
1)在PHP-FPM(在/etc/php/7.2/fpm/php.ini中)中修改cgi.fix_pathinfo = 1
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)最后重新启动服务(服务php7.2-fpm重新启动和sudo服务nginx重新启动)。