php - 如何使用 opencart 1.5.5 设置 nginx?

标签 php nginx opencart

可以将 nginx 与 OpenCart 一起使用吗?我正在使用以下 nginx 区域:

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;
        }
}

但是当我访问 shop.local 时,我重定向到 shop.local/install/index.php 并且 nginx 向我抛出错误 404。我的有什么问题吗?配置?

最佳答案

试试这个:

# 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;
    }
}

关于php - 如何使用 opencart 1.5.5 设置 nginx?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27133513/

相关文章:

php - 拉维尔 5 : How can I add seeder class to autoload?

php - Mysql_result() 需要参数 1 WARNING

symfony - 使用 Memcached 进行 session 时打开的文件太多

mod-rewrite - 从 URL 中删除特定的查询参数

php - OpenCart 类别未显示

php - 如何在opencart中检查属于特定产品的属性

php - 如何修复网络解决方案 ssl 代理的错误

python Tornado 处理程序 IO 阻塞整个服务器网络

.htaccess - nginx 上的 OpenCart

php - 检查 OpenCart 中的购物车是否为空