Skip to content

Commit e19bb6f

Browse files
committed
initial draft
1 parent 16b1296 commit e19bb6f

File tree

1 file changed

+34
-99
lines changed

1 file changed

+34
-99
lines changed

docs/ecommerce-applications/magento-2/how-to-configure-remote-storage-for-magento-2-x.md

Lines changed: 34 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ This can be useful for many reasons, such as:
2222

2323
Configuring Magento 2 to start storing files in your bucket is done using a single command.
2424

25+
**Hypernode Object Storage**
26+
```bash
27+
something something?
28+
```
29+
2530
**AWS S3**
2631

2732
```bash
@@ -55,124 +60,54 @@ Instead of running (which is Magento's official way to do this):
5560
bin/magento remote-storage:sync
5661
```
5762

58-
One can run the following instead to really speed up the process:
63+
you can run the following to really speed up the process:
64+
65+
```bash
66+
hypernode-object-storage objects sync pub/media/ s3://my_bucket_name/media/
67+
hypernode-object-storage objects sync var/import_export s3://my_bucket_name/import_export
68+
```
69+
70+
`hypernode-object-storage objects sync` will run a sync process in the background for you,
71+
and will tell you what the PID of that process is. With the PID you can run the following
72+
command to check up on the progress of the sync:
73+
74+
```bash
75+
hypernode-object-storage objects show PID
76+
```
77+
78+
Alternatively, you can run the `aws s3 sync` command directly:
5979

6080
```bash
6181
aws s3 sync pub/media/ s3://my_bucket_name/media/
6282
aws s3 sync var/import_export s3://my_bucket_name/import_export
6383
```
6484

65-
This is much faster than Magento's built-in sync, because `aws s3 sync` uploads files concurrently.
85+
In any case, that is much faster than Magento's built-in sync, because `aws s3 sync` uploads files concurrently.
6686

6787
## The storage flag file in the bucket
6888

6989
Magento's S3 implementation creates a test file called `storage.flag`, which is basically created to test if the connection works. So this is not a magic file to mark anything ([source](https://github.com/magento/magento2/blob/6f4805f82bb7511f72935daa493d48ebda3d9039/app/code/Magento/AwsS3/Driver/AwsS3.php#L104)).
7090

7191
## Serving assets from your S3 bucket
7292

73-
To start serving media assets from your S3 bucket, you need to make some adjustments to your nginx configuration. Create the following file at `/data/web/nginx/example.com/server.assets.conf` for each relevant vhost:
74-
75-
```nginx
76-
set $backend "haproxy";
77-
78-
location @object_storage_fallback {
79-
# Proxy to object storage
80-
set $bucket "my_bucket_name";
81-
proxy_cache_key "$bucket$uri";
82-
proxy_cache_valid 200 302 7d;
83-
proxy_cache_methods GET HEAD;
84-
proxy_cache_background_update on;
85-
proxy_cache_use_stale updating;
86-
proxy_cache asset_cache;
87-
resolver 8.8.8.8;
88-
proxy_pass https://$bucket.s3.amazonaws.com$uri;
89-
proxy_pass_request_body off;
90-
proxy_pass_request_headers off;
91-
proxy_intercept_errors on;
92-
proxy_hide_header "x-amz-id-2";
93-
proxy_hide_header "x-amz-request-id";
94-
proxy_hide_header "x-amz-storage-class";
95-
proxy_hide_header "x-amz-server-side-encryption";
96-
proxy_hide_header "Set-Cookie";
97-
proxy_ignore_headers "Set-Cookie";
98-
add_header Cache-Control "public";
99-
add_header X-Frame-Options "SAMEORIGIN";
100-
add_header X-Cache-Status $upstream_cache_status;
101-
expires +1y;
102-
103-
# If object storage fails, fallback to PHP handler
104-
error_page 404 = @asset_fallback;
105-
error_page 403 = @asset_fallback;
106-
}
107-
108-
location @php_asset_fallback {
109-
# Handle with phpfpm
110-
rewrite ^/media /get.php?$args last;
111-
rewrite ^/static/(version\d*/)?(.*)$ /static.php?resource=$2 last;
112-
echo_exec @phpfpm;
113-
}
114-
115-
location @haproxy {
116-
# Handle with haproxy
117-
include /etc/nginx/proxy_to_haproxy.conf;
118-
proxy_pass http://127.0.0.1:8080;
119-
}
120-
121-
location @asset_fallback {
122-
try_files "" $asset_fallback_handler;
123-
}
93+
To start serving media assets from your S3 bucket, you need to make some adjustments to your nginx configuration. Luckily, `hypernode-manage-vhosts` does this for you! If you are using Hypernode's object storage solution, all you need to do is run the following for relevant vhosts:
12494

125-
location ~ ^/static/ {
126-
expires max;
127-
128-
# Remove signature of the static files that is used to overcome the browser cache
129-
location ~ ^/static/version\d*/ {
130-
rewrite ^/static/version\d*/(.*)$ /static/$1 last;
131-
}
132-
133-
location ~* \.(ico|jpg|jpeg|png|gif|svg|svgz|webp|avif|avifs|js|css|eot|ttf|otf|woff|woff2|html|json|webmanifest)$ {
134-
add_header Cache-Control "public";
135-
add_header X-Frame-Options "SAMEORIGIN";
136-
expires +1y;
137-
138-
try_files $uri $uri/ @asset_fallback;
139-
}
140-
location ~* \.(zip|gz|gzip|bz2|csv|xml)$ {
141-
add_header Cache-Control "no-store";
142-
add_header X-Frame-Options "SAMEORIGIN";
143-
expires off;
144-
145-
try_files $uri $uri/ @asset_fallback;
146-
}
147-
try_files $uri $uri/ @asset_fallback;
148-
add_header X-Frame-Options "SAMEORIGIN";
149-
}
95+
```bash
96+
hmv example.com --object-storage
97+
```
15098

151-
location /media/ {
152-
try_files $uri $uri/ @asset_fallback;
99+
In the case that you're using custom object storage, such as Amazon's S3, you will need to supply the bucket name and the bucket URL yourself:
100+
```bash
101+
hmv example.com --object-storage --object-storage-bucket mybucket --object-storage-url https://example_url.com
102+
```
153103

154-
location ~ ^/media/theme_customization/.*\.xml {
155-
deny all;
156-
}
104+
If you have previously set your own custom bucket name and URL, but have since switched to Hypernode's object storage solution, then you can use the `--object-storage-defaults` flag to force overwrite your values to Hypernode's default ones:
157105

158-
location ~* \.(ico|jpg|jpeg|png|gif|svg|svgz|webp|avif|avifs|js|css|swf|eot|ttf|otf|woff|woff2)$ {
159-
add_header Cache-Control "public";
160-
add_header X-Frame-Options "SAMEORIGIN";
161-
expires +1y;
162-
try_files $uri $uri/ @object_storage_fallback;
163-
}
164-
location ~* \.(zip|gz|gzip|bz2|csv|xml)$ {
165-
add_header Cache-Control "no-store";
166-
add_header X-Frame-Options "SAMEORIGIN";
167-
expires off;
168-
try_files $uri $uri/ @object_storage_fallback;
169-
}
170-
add_header X-Frame-Options "SAMEORIGIN";
171-
}
106+
```bash
107+
hmv example.com --object-storage --object-storage-defaults
172108
```
173109

174-
Make sure to change the string `my_bucket_name` to the name of your bucket and keep in mind that your bucket URL might be different depending on your AWS region. For example, you might need to change it from `https://$bucket.s3.amazonaws.com$uri` to `https://s3.amazonaws.com/$bucket$uri` instead.
175-
Furthermore, ensure that your S3 bucket policies are configured correctly, so that only `/media` is publicly readable. For example:
110+
Furthermore, if you're using Amazon S3 as your bucket, ensure that your S3 bucket policies are configured correctly, so that only `/media` is publicly readable. For example:
176111

177112
```json
178113
{

0 commit comments

Comments
 (0)