Magento2上线nignx配置文件的万精油配置

nginx

server
{
    listen 80;
    server_name www.xxx.com;
    index index.php index.html index.htm default.php default.htm default.html;
    root /www/wwwroot/www.xxx.com;
    
    #SSL-START SSL相关配置,请勿删除或修改下一行带注释的404规则
    #error_page 404/404.html;
    #SSL-END
    
    #ERROR-PAGE-START  错误页配置,可以注释、删除或修改
    #error_page 404 /404.html;
    #error_page 502 /502.html;
    #ERROR-PAGE-END
    
    #PHP-INFO-START  PHP引用配置,可以注释或修改
    include enable-php-72.conf;
    #PHP-INFO-END
    
    #REWRITE-START URL重写规则引用,修改后将导致面板设置的伪静态规则失效
    include /www/server/panel/vhost/rewrite/www.xxx.com.conf;
    #REWRITE-END
    
      #禁止访问的文件或目录
    location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md)
    {
        return 404;
    }
    
    #一键申请SSL证书验证目录相关设置
    location ~ \.well-known{
        allow all;
    }
    
    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
    {
        expires      30d;
        error_log off;
        access_log /dev/null;
    }
    
    location ~ .*\.(js|css)?$
    {
        expires      12h;
        error_log off;
        access_log /dev/null; 
    }
    
    autoindex off;
# disable_symlinks on;
charset off;
#charset utf-8;
location /setup {
    try_files $uri $uri/ @setup;
}

location @setup {
    rewrite /setup /setup/index.php;
}

location / {
    try_files $uri $uri/ /index.php$is_args$args;
}
 
location /pub {
if ($request_method = 'OPTIONS') {
        add_header 'Access-Control-Allow-Origin' '*';
        add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
    
        add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
  
        # Tell client that this pre-flight info is valid for 20 days
    
        add_header 'Access-Control-Max-Age' 1728000;
        add_header 'Content-Type' 'text/plain; charset=utf-8';
        add_header 'Content-Length' 0;
        return 204;
     }
     if ($request_method = 'POST') {
        add_header 'Access-Control-Allow-Origin' '*';
        add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
        add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
        add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
     }
     if ($request_method = 'GET') {
        add_header 'Access-Control-Allow-Origin' '*';
        add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
        add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
        add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
     }
    try_files $uri @static;
    
}

location @static {
    rewrite ^/pub/static/(version\d*/)?(.*)$ /pub/static.php?resource=$2 last;
}

location /pub/media {
    try_files $uri/ @mediahandler;
}
location @mediahandler {
    rewrite / /get.php;
}

location /pub/media/customer {
    deny all;
}
location /pub/media/downloadable {
    deny all;
}
location ~ /pub/media/theme_customization/.*\.xml$ {
    deny all;
}
location ~ /pub/errors/.*\.(xml|phtml)$ {
    deny all;
}
location /sitemap.xml {
    alias /www/wwwroot/public_html/sitemaps/sitemap.xml;
}
 location /robots.txt {
    alias /www/wwwroot/public_html/robots.txt;
}
gzip on;

gzip_disable "msie6";

gzip_comp_level 6;

gzip_min_length 1100;

gzip_buffers 16 8k;

gzip_proxied any;

gzip_types
    text/plain
    text/css
    text/js
    text/xml
    text/javascript
    application/javascript
    application/x-javascript
    application/json
    application/xml
    application/xml+rss
    image/svg+xml;

gzip_vary on;
    #禁止访问的文件或目录
    location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md)
    {
        return 404;
}
    access_log  /www/wwwlogs/www.xxx.com.log;
    error_log  /www/wwwlogs/www.xxx.com.error.log;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Magento 2 中,您可以使用 Redis 作为缓存后端以提高网站性能。以下是在 Magento 2 中配置 Redis 的步骤: 1. 安装 Redis: 在 Ubuntu 上,您可以使用以下命令安装 Redis: ``` sudo apt-get update sudo apt-get install redis-server ``` 您可以在其他操作系统上使用适当的命令安装 Redis。 2. 安装 Redis PHP 扩展: 您需要安装 Redis PHP 扩展才能在 Magento 2 中使用 Redis 缓存后端。您可以使用以下命令在 Ubuntu 上安装 Redis PHP 扩展: ``` sudo apt-get install php-redis ``` 您可以在其他操作系统上使用适当的命令安装 Redis PHP 扩展。 3. 在 Magento 2 中配置 Redis: 在 Magento 2 中配置 Redis 缓存后端需要编辑 `app/etc/env.php` 文件。使用以下命令打开该文件: ``` sudo nano /var/www/html/app/etc/env.php ``` 在该文件中,找到以下行: ``` 'cache' => [ 'frontend' => [ 'default' => [ 'backend' => 'Magento\Framework\Cache\Backend\File', 'frontend' => 'Magento\Framework\Cache\Frontend\Decorator\TagScope', 'frontend_options' => [ 'cache_id_prefix' => 'mage', ], ], 'page_cache' => [ 'backend' => 'Magento\Framework\Cache\Backend\File', 'frontend' => 'Magento\Framework\Cache\Frontend\Decorator\TagScope', 'frontend_options' => [ 'cache_id_prefix' => 'mage', ], ], ], ], ``` 替换上述 `cache` 部分的内容,使其与以下内容匹: ``` 'cache' => [ 'frontend' => [ 'default' => [ 'backend' => 'Cm_Cache_Backend_Redis', 'backend_options' => [ 'server' => '127.0.0.1', 'port' => '6379', 'database' => '0', 'password' => '', 'compress_data' => '1', 'compression_lib' => 'gzip', 'persistent' => '', 'force_standalone' => '0', 'connect_retries' => '1', 'read_timeout' => '10', 'automatic_cleaning_factor' => '0', 'compress_tags' => '1', 'prefix' => '', 'serializer' => '', ], 'frontend' => 'Magento\Framework\Cache\Frontend\Decorator\TagScope', 'frontend_options' => [ 'cache_id_prefix' => 'mage', ], ], 'page_cache' => [ 'backend' => 'Cm_Cache_Backend_Redis', 'backend_options' => [ 'server' => '127.0.0.1', 'port' => '6379', 'database' => '1', 'password' => '', 'compress_data' => '0', 'compression_lib' => '', 'persistent' => '', 'force_standalone' => '0', 'connect_retries' => '1', 'read_timeout' => '10', 'automatic_cleaning_factor' => '0', 'compress_tags' => '1', 'prefix' => '', 'serializer' => 'None', ], 'frontend' => 'Magento\Framework\Cache\Frontend\Decorator\TagScope', 'frontend_options' => [ 'cache_id_prefix' => 'mage', ], ], ], ], ``` 在上述代码中,您需要更改以下内容: - `'server' => '127.0.0.1'`:更改为您的 Redis 服务器的 IP 地址或主机名。 - `'port' => '6379'`:更改为您的 Redis 服务器的端口号。 - `'database' => '0'` 和 `'database' => '1'`:更改为您要在 Redis 中使用的数据库的编号。 4. 清除 Magento 2 缓存: 使用以下命令清除 Magento 2 缓存: ``` php bin/magento cache:clean ``` 现在,您已经成功地在 Magento 2 中配置了 Redis 缓存后端。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值