preSTASHOP NGINX +重写规则 [英] PRESTASHOP NGINX + REWRITE RULES

查看:335
本文介绍了preSTASHOP NGINX +重写规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是寻找这个组合很好的解决方案,并按照以下后:

I've being searching for a good solution for this combination and after following these:

HTTP:// WWW。 phamviet.net/2012/06/03/$p$pstashop-rewrite-url-on-nginx/ http://www.nginxtips.com/nginx-configuration-for-prestashop / <一href="http://www.$p$pstashop.com/forums/topic/307168-$p$pstashop-1562-rewrite-urls-over-nginx-install/?hl=%2Bnginx#entry1554501" rel="nofollow">http://www.$p$pstashop.com/forums/topic/307168-$p$pstashop-1562-rewrite-urls-over-nginx-install/?hl=%2Bnginx#entry1554501

没有人似乎为我工作在所有...于是我开始尝试:

none of them seemed to work for me at all... so I started experimenting:

配置SSL后,CloudFlare的,等等...

After configuring SSL, CloudFlare, etc....

这是我的尝试:

server {
  listen 80;
  server_name mysuperdomain.com www.mysuperdomain.com;
  rewrite ^ https://$server_name$request_uri? permanent;
}

server {
  # listen 80 deferred; # for Linux
  # listen 80 accept_filter=httpready; # for FreeBSD
  listen 443;

  # The host name to respond to
  server_name mysuperdomain.com *.mysuperdomain.com;

  # Path for static files
  root /sites/mysuperdomain.com/public;

  ssl on;
  ssl_certificate /etc/nginx/ssl/ssl.pem;
  ssl_certificate_key /etc/nginx/ssl/ssl.key;

  # Try static files first, then php
  index index.html index.htm index.php;

  # Specific logs for this vhost
  access_log /sites/mysuperdomain.com/log/log-access.log;
  error_log  /sites/mysuperdomain.com/log/log-error.log error;

  #Specify a charset
  charset utf-8;

  # Redirect needed to "hide" index.php
  location / {
    rewrite ^/([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/$1/$1$2$3.jpg break;
    rewrite ^/([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/$1/$2/$1$2$3$4.jpg break;
    rewrite ^/([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/$1/$2/$3/$1$2$3$4$5.jpg break;
    rewrite ^/([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/$1/$2/$3/$4/$1$2$3$4$5$6.jpg break;
    rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/$1/$2/$3/$4/$5/$1$2$3$4$5$6$7.jpg break;
    rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/$1/$2/$3/$4/$5/$6/$1$2$3$4$5$6$7$8.jpg break;
    rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/$1/$2/$3/$4/$5/$6/$7/$1$2$3$4$5$6$7$8$9.jpg break;
    rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/$1/$2/$3/$4/$5/$6/$7/$8/$1$2$3$4$5$6$7$8$9$10.jpg break;
    if (-e $request_filename){
        rewrite ^(.*)$ /index.php break;
    }
    try_files $uri $uri/ /index.php?q=$uri&$args;
}

location /c {
    rewrite ^/c/([0-9]+)(\-[\.*_a-zA-Z0-9-]*)(-[0-9]+)?/.+\.jpg$ /img/$1$2$3.jpg break;
    rewrite ^/c/([a-zA-Z_-]+)(-[0-9]+)?/.+\.jpg$ /img/$1$2.jpg break;
}
location /images_ie {
    rewrite ^/images_ie/?([^/]+)\.(jpe?g|png|gif)$ /js/jquery/plugins/fancybox/images/$1.$2 break;
}

# Don't log robots.txt or favicon.ico files
location ~* ^/(favicon.ico|robots.txt)$ {
    access_log off;
    log_not_found off;
}
# Custom 404 page
error_page 404 /index.php?controller=404;

location ~* ^.+.(gif|jpg|jpeg|png|wmv|avi|mpg|mpeg|mp4|htm|html|js|css|mp3|swf|ico|flv|xml) {
    access_log off;
    expires 30d;
}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;

    # With php5-cgi alone:
    # fastcgi_pass 127.0.0.1:9000;
    # With php5-fpm:
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_intercept_errors on;
    fastcgi_buffers 8 16k;
    fastcgi_buffer_size 32k;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
}

# Deny access to .htaccess
location ~ /\.ht {
    deny all;
}

#PHPMYADMIN
location /phpmyadmin {
 root /usr/share/;
 index index.php index.html index.htm;
 location ~ ^/phpmyadmin/(.+\.php)$ {
   try_files $uri =404;
   root /usr/share/;
   fastcgi_pass unix:/var/run/php5-fpm.sock;
   fastcgi_index index.php;
   fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
   include fastcgi_params;
}
location ~* ^/phpmyadmin/(.+\.(jpeg|jpg|png|css|gif|ico|js|html|xml|txt))$ {
   root /usr/share/;
}
}
location /phpMyAdmin {
 rewrite ^/* /phpmyadmin last;
}

# Include the basic h5bp config set
include h5bp/basic.conf;
}

它似乎只对类别而不是单个产品页面和等。

It seems to only work for categories but not for individual products pages and such.

当你打的主要领域或进入主页,它会显示下载主页的index.php代替。

When you hit the main domain or go to the home page, it will download index.php instead of showing the home page.

那么的一点点帮助将是惊人的!

So a little bit of help would be amazing!

推荐答案

这是为我工作很好:

server {
  fastcgi_read_timeout 180s;
  listen  80;
  listen  443 ssl;
  server_name example.com www.example.com;
  ssl on;
  ssl_certificate /etc/nginx/ssl/example.com.crt;
  ssl_certificate_key /etc/nginx/ssl/example.com.key;

  error_log /srv/example.com/log/error.log;
  root /srv/example.com/html;

  location / {
      index index.html index.htm index.php;
  }

  location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml)$ {
      access_log        off;
      log_not_found     off;
      expires           360d;
  }

  location ~ /\. {
      access_log off;
      log_not_found off; 
      deny all;
  }

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

  location = /robots.txt {
      allow all;
      log_not_found off;
      access_log off;
  }

  location ~ \.php$ {
      include /etc/nginx/fastcgi_params;
      fastcgi_pass  127.0.0.1:9010;
      fastcgi_index index.php;
      fastcgi_param SCRIPT_FILENAME /srv/example.com/html$fastcgi_script_name;
      fastcgi_param PHP_VALUE max_execution_time=180;
  }

  # Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).
  location ~ /\. {
      deny all;
      access_log off;
      log_not_found off;
  }

  rewrite ^/api/?(.*)$ /webservice/dispatcher.php?url=$1 last;

  rewrite "^/c/([0-9]+)(\-[_a-zA-Z0-9-]*)/(.*)\.jpg$" /img/c/$1$2.jpg last;
  rewrite "^/c/([_a-zA-Z-]+)/(.*)\.jpg$" /img/c/$1.jpg last;

  rewrite "^/([a-z0-9]+)\-([a-z0-9]+)(\-[_a-zA-Z0-9-]*)/(\P{M}\p{M}*)*\.jpg$" /img/p/$1-$2$3.jpg last;
  rewrite "^/([0-9]+)\-([0-9]+)/(\P{M}\p{M}*)*\.jpg$" /img/p/$1-$2.jpg last;
  rewrite "^/([0-9])(\-[_a-zA-Z0-9-]*)?/(\P{M}\p{M}*)*\.jpg$" /img/p/$1/$1$2.jpg last;
  rewrite "^/([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?/(\P{M}\p{M}*)*\.jpg$" /img/p/$1/$2/$1$2$3.jpg last;
  rewrite "^/([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?/(\P{M}\p{M}*)*\.jpg$" /img/p/$1/$2/$3/$1$2$3$4.jpg last;
  rewrite "^/([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?/(\P{M}\p{M}*)*\.jpg$" /img/p/$1/$2/$3/$4/$1$2$3$4$5.jpg last;
  rewrite "^/([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?/(\P{M}\p{M}*)*\.jpg$" /img/p/$1/$2/$3/$4/$5/$1$2$3$4$5$6.jpg last;
  rewrite "^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?/(\P{M}\p{M}*)*\.jpg$" /img/p/$1/$2/$3/$4/$5/$6/$1$2$3$4$5$6$7.jpg last;
  rewrite "^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?/(\P{M}\p{M}*)*\.jpg$" /img/p/$1/$2/$3/$4/$5/$6/$7/$1$2$3$4$5$6$7$8.jpg last;
  rewrite "^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?/(\P{M}\p{M}*)*\.jpg$" /img/p/$1/$2/$3/$4/$5/$6/$7/$8/$1$2$3$4$5$6$7$8$9.jpg last;

  rewrite "^/([0-9]+)\-(\P{M}\p{M}*)+\.html(.*)$" /index.php?controller=product&id_product=$1$3 last;
  rewrite "^/([0-9]+)\-([a-zA-Z0-9-]*)(.*)$" /index.php?controller=category&id_category=$1$3 last;
  rewrite "^/([a-zA-Z0-9-]*)/([0-9]+)\-([a-zA-Z0-9-]*)\.html(.*)$" /index.php?controller=product&id_product=$2$4 last;
  rewrite "^/([0-9]+)__([a-zA-Z0-9-]*)(.*)$" /index.php?controller=supplier&id_supplier=$1$3 last;
  rewrite "^/([0-9]+)_([a-zA-Z0-9-]*)(.*)$" /index.php?controller=manufacturer&id_manufacturer=$1$3 last;
  rewrite "^/content/([0-9]+)\-([a-zA-Z0-9-]*)(.*)$" /index.php?controller=cms&id_cms=$1$3 last;
  rewrite "^/content/category/([0-9]+)\-([a-zA-Z0-9-]*)(.*)$" /index.php?controller=cms&id_cms_category=$1$3 last;
  rewrite "^/module/([_a-zA-Z0-9-]*)/([_a-zA-Z0-9-]*)$" /index.php?fc=module&module=$1&controller=$2 last;

  rewrite ^/page-not-found$ /index.php?controller=404 last;
  rewrite ^/address$ /index.php?controller=address last;  
  rewrite ^/addresses$ /index.php?controller=addresses last;
  rewrite ^/authentication$ /index.php?controller=authentication last;
  rewrite ^/best-sales$ /index.php?controller=best-sales last;
  rewrite ^/cart$ /index.php?controller=cart last;
  rewrite ^/contact-us$ /index.php?controller=contact-form last;
  rewrite ^/discount$ /index.php?controller=discount last;
  rewrite ^/guest-tracking$ /index.php?controller=guest-tracking last;
  rewrite ^/order-history$ /index.php?controller=history last;
  rewrite ^/identity$ /index.php?controller=identity last;
  rewrite ^/manufacturers$ /index.php?controller=manufacturer last;
  rewrite ^/my-account$ /index.php?controller=my-account last;
  rewrite ^/new-products$ /index.php?controller=new-products last;
  rewrite ^/order$ /index.php?controller=order last;
  rewrite ^/order-follow$ /index.php?controller=order-follow last;
  rewrite ^/quick-order$ /index.php?controller=order-opc last;
  rewrite ^/order-slip$ /index.php?controller=order-slip last;
  rewrite ^/password-recovery$ /index.php?controller=password last;
  rewrite ^/prices-drop$ /index.php?controller=prices-drop last;  
  rewrite ^/search$ /index.php?controller=search last;
  rewrite ^/sitemap$ /index.php?controller=sitemap last;
  rewrite ^/stores$ /index.php?controller=stores last;  
  rewrite ^/supplier$ /index.php?controller=supplier last;

  location ~* \.(gif)$ {
    expires 2592000s;
  }

  location ~* \.(jpeg|jpg)$ {
    expires 2592000s;
  }

  location ~* \.(png)$ {
    expires 2592000s;
  }

  location ~* \.(css)$ {
    expires 604800s;
  }

  location ~* \.(js|jsonp)$ {
    expires 604800s;
  }

  location ~* \.(js)$ {
    expires 604800s;
  }

  location ~* \.(ico)$ {
    expires 31536000s;
  }
}

这篇关于preSTASHOP NGINX +重写规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆