官术网_书友最值得收藏!

  • NGINX Cookbook
  • Tim Butler
  • 241字
  • 2021-07-03 00:04:26

How to do it...

Thankfully, Magento provides a fairly functional NGINX sample configuration (located in the root of the Magento source folder) to get started with. I've located the files within the /var/www/html directory, which will be known as MAGE_ROOT.

Magento provides a basic configuration out of the box, which only requires a few small changes. However, I prefer to use my own configuration which I find easier to follow. Here's how I do it:

server { 
    listen       80; 
    server_name  magento.nginxcookbook.com; 
    set $MAGE_ROOT /var/www/html; 
 
    access_log  /var/log/nginx/magento.access.log  combined; 
    index index.php; 
 
    root   $MAGE_ROOT/pub/; 
 
    location / { 
        try_files $uri $uri/ /index.php?$args; 
    } 
    location ~ ^/(setup|update) { 
        root $MAGE_ROOT; 
        location ~ ^/(setup|update)/index.php { 
            fastcgi_pass   unix:/var/run/php7.0-fpm.sock; 
            fastcgi_index  index.php; 
            fastcgi_param  SCRIPT_FILENAME  
$document_root$fastcgi_script_name; include fastcgi_params; } location ~ ^/(setup|update)/(?!pub/). { deny all; } location ~ ^/(setup|update)/pub/ { add_header X-Frame-Options "SAMEORIGIN"; } } location /static/ { expires max; if (!-f $request_filename) { rewrite ^/static/(version\d*/)?(.*)$
/static.php?resource=$2 last; } add_header X-Frame-Options "SAMEORIGIN"; } location /media/ { try_files $uri $uri/ /get.php?$args; location ~ ^/media/theme_customization/.*\.xml { deny all; } add_header X-Frame-Options "SAMEORIGIN"; } location ~ \.php$ { fastcgi_pass unix:/var/run/php7.0-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME
$document_root$fastcgi_script_name; include fastcgi_params; } }

As you can see, this is significantly more complex than a basic WordPress configuration. There are four main sections; the first is to handle the setup and updates, the second is to handle static media (for example, default Magento, CSS, and JavaScript), media files (for example, upload images), and finally how to process PHP files.

主站蜘蛛池模板: 房产| 平潭县| 曲松县| 沅江市| 武定县| 舒兰市| 清远市| 义马市| 开原市| 大庆市| 盈江县| 讷河市| 阿图什市| 积石山| 手游| 霸州市| 赤水市| 卢氏县| 米泉市| 灌阳县| 灵宝市| 大竹县| 饶阳县| 合江县| 宁河县| 郎溪县| 日土县| 河曲县| 讷河市| 织金县| 呈贡县| 都昌县| 黑水县| 巴林右旗| 太康县| 安顺市| 航空| 和顺县| 顺平县| 建瓯市| 内乡县|