Nginx下Magento伪静态规则,适用于LNMP一键包

本文介绍如何通过修改Nginx配置文件来部署Magento商店。具体步骤包括替换默认配置文件为Magento专用配置文件,并详细展示了如何设置文件夹权限、隐藏敏感文件及重定向规则等。最后介绍了重启Nginx服务的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

文件名为:magento.conf( 下载 ),将其放在 /usr/local/nginx/conf/ 文件夹下 
然后在 /usr/local/nginx/conf/vhost/www.yourname.com.conf 中将 include none.conf;  换成 include magento.conf; 即可。 " B3 M( l8 {! g  e7 N
( ~) ^+ j  [1 M+ ~) b' K+ \
location / {
        index index.html index.php; ## Allow a static html file to be shown first
        try_files $uri $uri/ @handler; ## If missing pass the URI to Magento's front handler
        expires 30d; ## Assume all files are cachable
    }

    ## These locations would be hidden by .htaccess normally
    location /app/                { deny all; }
    location /includes/           { deny all; }
    location /lib/                { deny all; }
    location /media/downloadable/ { deny all; }
    location /pkginfo/            { deny all; }
    location /report/config.xml   { deny all; }
    location /var/                { deny all; }

    location /var/export/ { ## Allow admins only to view export folder
        auth_basic           "Restricted"; ## Message shown in login window
        auth_basic_user_file htpasswd; ## See /etc/nginx/htpassword
        autoindex            on;
    }
      location  /. { ## Disable .htaccess and other hidden files
        return 404;
    }

    location @handler { ## Magento uses a common front handler
        rewrite / /index.php;
    }

    location ~ .php/ { ## Forward paths like /js/index.php/x.js to relevant handler
        rewrite ^(.*.php)/ $1 last;
    }


最后是重启nginx:   k! {' D2 |9 a4 r4 `& \
( \3 u" T2 J/ s' B; l

/etc/init.d/nginx restart

/usr/local/nginx/sbin/nginx -s reload

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值