搜索
开启辅助访问 切换到宽版

QQ登录

只需一步,快速开始

扫一扫,访问微社区

注册 找回密码
查看: 16556|回复: 4
打印 上一主题 下一主题

nginx下opencart的伪静态配置

[复制链接]
跳转到指定楼层
楼主
发表于 2013-8-30 10:50:57 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
照着百度上的教程给我的阿里云配置了LNMP,结果本来在apache下适用的.htaccess不能用了,头疼了一两天呢。度娘和谷歌都不给力啊。经过2天起早贪黑的奋战,终于解决了。下面是方法:  

伪静态配置流程

      首先,我们需要找到/usr/local/nginx/conf下面的“域名.conf“,这个是虚拟机的配置文件,我们就从这儿入手,以www.mlbz.cn为例:

#vi /usr/local/nginx/conf/www.mlbz.cn.conf

在配置文件中插入opencart伪静态规则:

(注意把www.mlbz.con修改成自己的域名)
  1. location / {
  2.     if ($host != ‘[url]www.mlbz.cn[/url]’) {
  3.              rewrite ^/(.*)$ [url]https://www.mlbz.cn/[/url]$1 permanent;
  4.      }
  5.      try_files $uri @opencart;
  6. }

  7. location @opencart {
  8.      rewrite ^/(.+)$ /index.php?_route_=$1 last;
  9. }

  10.      location /admin/ {
  11.      index index.php;
  12.      }

  13. location ~* (\.(tpl|ini))$ {
  14.        deny all;
  15. }
复制代码


伪静态规则具体的插入位置:

  1. log_format  mlbz.cn  ‘$remote_addr – $remote_user [$time_local] "$request" ‘
  2.              ‘$status $body_bytes_sent "$http_referer" ‘
  3.              ‘"$http_user_agent" $http_x_forwarded_for’;
  4. server
  5.     {
  6.         listen       80;
  7.         server_name mlbz.cn mlbz.cn [url]www.mlbz.cn[/url];
  8.         index index.html index.htm index.php default.html default.htm default.php;
  9.         root  /home/wwwroot/mlbz.cn;

  10. location / {
  11.     if ($host != ‘[url]www.mlbz.cn[/url]’) {
  12.              rewrite ^/(.*)$ [url]https://www.mlbz.cn/[/url]$1 permanent;
  13.      }
  14.      try_files $uri @opencart;
  15. }

  16. location @opencart {
  17.      rewrite ^/(.+)$ /index.php?_route_=$1 last;
  18. }

  19.      location /admin/ {
  20.      index index.php;
  21.      }

  22. location ~* (\.(tpl|ini))$ {
  23.        deny all;
  24. }
  25.         location ~ .*\.(php|php5)?$
  26.             {
  27.                 try_files $uri =404;
  28.                 fastcgi_pass  unix:/tmp/php-cgi.sock;
  29.                 fastcgi_index index.php;
  30.                 include fcgi.conf;
  31.             }

  32.         location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
  33.             {
  34.                 expires      30d;
  35.             }

  36.         location ~ .*\.(js|css)?$
  37.             {
  38.                 expires      12h;
  39.             }

  40.         access_log  /home/wwwlogs/mlbz.cn.log  mlbz.cn;
  41.     }
复制代码


看起来挺复杂是吧?如果你用的也是lnmp.org上的安装包,就是把配置文件中的include *****.conf; 字段给替换成上文中的伪静态规则而已。

如果是apache环境请参考

https://bbs.opencart.cn/thread-86-1-1.html

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
收藏收藏1 分享分享 支持支持 反对反对
回复

使用道具 举报

沙发
 楼主| 发表于 2014-11-13 23:11:02 | 只看该作者
如果上面的不清楚的可以用下面的这个方法:

第一步:

在 /usr/local/nginx/conf/vhost 下面建立文件 www.opencart.cn.conf(可以安装你的域名起名字)
内容如下:

  1. server
  2.         {
  3.                 listen 80;
  4.                 #listen [::]:80;
  5.                 server_name opencart.cn www.opencart.cn ;   ## 这里的域名请修改为你自己的域名
  6.                 index index.html index.htm index.php default.html default.htm default.php;
  7.                 root  /home/wwwroot/www.opencart.cn;    ## 这里是域名网站对应的文件路径

  8.                 location / {
  9.                                      if ($host != 'www.opencart.cn') {
  10.                                              rewrite ^/(.*)$ [url]https://www.opencart.cn/[/url]$1 permanent;
  11.                                      }
  12.                                      try_files $uri @opencart;
  13.                                  }
  14.                                
  15.                                  location @opencart {
  16.                                      rewrite ^/(.+)$ /index.php?_route_=$1 last;
  17.                                  }
  18.                                
  19.                                      location /admin/ {
  20.                                      index index.php;
  21.                                      }
  22.                                
  23.                                  location ~* (\.(tpl|ini))$ {
  24.                                        deny all;
  25.                                  }
  26.                                

  27.                 #error_page   404   /404.html;
  28.                 location ~ [^/]\.php(/|$)
  29.                         {
  30.                                 # comment try_files $uri =404; to enable pathinfo
  31.                                 try_files $uri =404;
  32.                                 fastcgi_pass  unix:/tmp/php-cgi.sock;
  33.                                 fastcgi_index index.php;
  34.                                 include fastcgi.conf;
  35.                                 #include pathinfo.conf;
  36.                         }

  37.                 location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
  38.                         {
  39.                                 expires      30d;
  40.                         }

  41.                 location ~ .*\.(js|css)?$
  42.                         {
  43.                                 expires      12h;
  44.                         }

  45.                 access_log  /home/wwwlogs/www.opencart.cn.log  access;
  46.         }
复制代码


第二步:
重启NGINX   
  1.   service nginx restart
复制代码

或者
  1. /etc/init.d/nginx restart
复制代码



收工,洗洗睡觉了。
回复 支持 反对

使用道具 举报

板凳
发表于 2018-7-19 15:12:08 | 只看该作者
我的服务器里面是nginx-1.12,然后/conf/这个文件夹里面,没有vhost这个文件夹
回复 支持 反对

使用道具 举报

地板
发表于 2018-7-19 15:34:00 | 只看该作者
直接在conf文件夹里面新建了 我的域名.conf  内容也复制了, 重启后没生效
回复 支持 反对

使用道具 举报

5#
发表于 2018-7-19 15:34:33 | 只看该作者
还有没有什么方法??
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

站长推荐 上一条 /1 下一条

QQ|手机版|OpenCart - 中文官方网站 ( 蜀ICP备09033774号|人工智能

GMT+8, 2024-4-20 05:35 , Processed in 0.098619 second(s), 35 queries , Gzip On.

快速回复 返回顶部 返回列表