【问题标题】:Joomla with Nginx Rewrite SEF urlJoomla 与 Nginx 重写 SEF url
【发布时间】:2014-01-04 18:50:54
【问题描述】:

我正在使用带有 NGINX 和 PHP5-FPM 的 Ubuntu 12.04。我刚刚将我的 Joomla 网站从 Apache 迁移到 NGINX。但我认为重写规则效果不佳。

所有 SEF 链接都重写到主页,但在 url 栏中的链接似乎正确。

例如,如果我单击 example.com/a/b.html,它看起来像是转到 url 栏中的链接,但 homapage 正在加载。

感谢您的帮助。

/etc/nginx/sites-available/example.com 文件

server {
    listen 80;
    server_name example.com;
    #server_name_in_redirect off;

    #access_log /var/log/nginx/localhost.access_log main;
    #error_log /var/log/nginx/localhost.error_log info;

    root /var/www/example.com/public_html/;
    index index.php index.html index.htm default.html default.htm;
    # Support Clean (aka Search Engine Friendly) URLs
    location / {
            try_files $uri $uri/ /index.php?q=$request_uri;
    }

    # deny running scripts inside writable directories
    location ~* /(images|cache|media|logs|tmp)/.*\.(php|pl|py|jsp|asp|sh|cgi)$ {
            return 403;
            error_page 403 /403_error.html;
    }

    location ~ \.php$ {
            # With php5-fpm:
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            include fastcgi_params;
            #fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            }

    # caching of files 
    location ~* \.(ico|pdf|flv)$ {
            expires 1y;
    }

    location ~* \.(js|css|png|jpg|jpeg|gif|swf|xml|txt)$ {
            expires 14d;
    }

 }

nginx.conf

user www-data;
worker_processes 8;
pid /var/run/nginx.pid;

events {
worker_connections 1024;
# multi_accept on;
}

http {

##
# Basic Settings
##

sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 30;
types_hash_max_size 2048;
server_tokens off;

# server_names_hash_bucket_size 64;
# server_name_in_redirect off;

include /etc/nginx/mime.types;
default_type application/octet-stream;

##
# Logging Settings
##

access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;

##
# Gzip Settings
##

gzip on;
gzip_disable "msie6";

gzip_vary on;
# gzip_proxied any;
gzip_comp_level 6;
# gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

##
# nginx-naxsi config
##
# Uncomment it if you installed nginx-naxsi
##

#include /etc/nginx/naxsi_core.rules;

##
# nginx-passenger config
##
# Uncomment it if you installed nginx-passenger
##

#passenger_root /usr;
#passenger_ruby /usr/bin/ruby;


    ## Block spammers and other unwanted visitors  ##
    include /etc/nginx/blockips.conf;

##
# Virtual Host Configs
##

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
   }

【问题讨论】:

  • 嗯,我也遇到了同样的问题,你有没有设法解决这个问题?
  • 遗憾的是,我已经切换回 apache。

标签: joomla nginx rewrite


【解决方案1】:

是的 - 这个回复已经超过 3 年了,但不幸的是,在使用 NGINX 时,最新版本的 Joomla 也存在同样的问题......

我们在客户的一个网站上遇到了完全相同的问题。问题结果与 NGINX 服务器未设置的 PHP 的 $_SERVER 常量之一有关 - 在 Joomla 的许多地方使用该常量(即 `$_SERVER['PHP_SELF'])返回当前 URL .我们已经详细描述了这个问题以及如何解决它,here。

【讨论】:

  • 不幸的是,我在 freebsd 上使用 php56 根本无法使用它。这不是解决所有问题的方法。我还没有找到可行的解决方案。
【解决方案2】:

如果您使用的是子文件夹/虚拟主机,请尝试更改:

# Support Clean (aka Search Engine Friendly) URLs
location / {
        try_files $uri $uri/ /index.php?q=$request_uri;
}

到

# Support Clean (aka Search Engine Friendly) URLs
location /subfolder/ {
        try_files $uri $uri/ /subfolder/index.php?q=$request_uri;
}

【讨论】:

    【解决方案3】:

    您好,这是我的主机配置,可以与 Joomla 3.6.5 友好的 URL、Ubuntu 16.04、PHP7 和 nginx 配合使用:

    server {
            listen 80;
            server_name mydomain.com;
            root /var/www/html/mydomain;
            index index.php index.html index.htm default.html default.htm;
    
            location / {
                    try_files $uri $uri/ /index.php?$args;
            }
    
            location ~ \.php$ {
                    include fastcgi_params;
                    fastcgi_index index.php;
                    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
            }
    }
    

    【讨论】:

      【解决方案4】:

      我的解决方案是确保启用 php.ini 的这一部分:cgi.fix_pathinfo = 1。修复了$_SERVER['PHP_SELF']没有设置的问题。

      我不小心把它禁用了。

      cgi.fix_pathinfo 为 CGI 提供real PATH_INFO/PATH_TRANSLATED 支持。 PHP 以前的行为是将 PATH_TRANSLATED 设置为 SCRIPT_FILENAME,并且不了解 PATH_INFO 是什么。有关 PATH_INFO 的更多信息,请参阅 cgi 规范。将此设置为 1 将导致 PHP CGI 修复其路径以符合规范。设置为零会导致 PHP 像以前一样运行。默认值为 1。您应该修复脚本以使用 SCRIPT_FILENAME 而不是 PATH_TRANSLATED。 http://php.net/cgi.fix-pathinfo

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-10-26
        • 1970-01-01
        • 2011-12-14
        • 2013-06-05
        • 2012-06-05
        • 2015-06-12
        • 2012-10-28
        • 2013-03-16
        相关资源
        最近更新 更多