douhandie6615 2014-11-25 17:56
浏览 148

如何使用opencart 1.5.5设置nginx?

It is possible to use nginx with OpenCart? I am using following nginx zone:

server {
        listen 80;
        listen [::]:80;

        root /home/username/Development/shop.local;
        index index.php;

        server_name shop.local;

        location /image/data {
                autoindex on;
        }

        location /admin {
                index index.php;
        }

        location / {
                try_files $uri @opencart;
        }

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

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

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


        # Make sure files with the following extensions do not get loaded by nginx because nginx would display the source code, and these files can contain PASSWORDS!
        location ~* \.(engine|inc|info|install|make|module|profile|test|po|sh|.*sql|theme|tpl(\.php)?|xtmpl)$|^(\..*|Entries.*|Repository|Root|Tag|Template)$|\.php_ {
                deny all;
        }

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

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

        location ~ \.php$ {
                try_files $uri =404;
                include fastcgi_params;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        }
}

But when i visit shop.local i am getting redirecto to shop.local/install/index.php and nginx throws me an error 404. What's wrong with my config?

  • 写回答

1条回答 默认 最新

  • dqf60304 2015-01-14 06:48
    关注

    Try this one:

    # FORCE WWW
    server {
        server_name  site.com;
        rewrite ^(.*) http://www.domain.com$1 permanent;
    }
    # MAIN SERVER
    server {
        server_name  www.domain.com;
        listen 80;
        root /var/www/www.domain.com/public;
        index index.php index.html;
        location /image/data {
            autoindex on;
        }
        location /admin {
            index index.php;
        }
        location / {
            try_files $uri @opencart;
        }
        location @opencart {
            rewrite ^/(.+)$ /index.php?_route_=$1 last;
        }
        location = /favicon.ico {
            log_not_found off;
            access_log off;
        }
        location = /robots.txt {
            allow all;
            log_not_found off;
            access_log off;
        }
        # Make sure files with the following extensions do not get loaded by nginx because nginx would display the source code, and these files can contain PASSWORDS!
        location ~* \.(engine|inc|info|install|make|module|profile|test|po|sh|.*sql|theme|tpl(\.php)?|xtmpl)$|^(\..*|Entries.*|Repository|Root|Tag|Template)$|\.php_ {
            deny all;
        }
        # Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).
        location ~ /\. {
            deny all;
            access_log off;
            log_not_found off;
        }
        location ~*  \.(jpg|jpeg|png|gif|css|js|ico)$ {
            expires max;
            log_not_found off;
        }
        location ~ \.php$ {
            try_files $uri =404;
            include /etc/nginx/fastcgi_params;
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        }
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥100 求数学坐标画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站