Magento ist bekanntlich nicht wirklich Schnell, deshalb kann man mit einem Reverse Proxy vor dem Magento Webserver die Performance um einie Faktoren steigern.
Eine Haftung für dieses Beispiel wird nicht übernommen, bitte nicht an Produktiv Systemen ohne vorherigen Test Einsetzten.
Hier findet Ihr eine Anleitung wie Ihr NGINX als Reverse Proxy einsetzt ohne selbst an der Applikation was zu verändern.
1) NGINX Installieren
[shell]
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install nginx[/shell]
2) die Config Datei von Nginx editieren
[shell]
nano /etc/nginx/nginx.conf
[/shell]
und folgende änderungen durchführen:
[shell]
user www-data;
worker_processes 2;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
server_names_hash_bucket_size 64;
sendfile on;
tcp_nopush on;
keepalive_timeout 65;
tcp_nodelay on;
gzip on;
gzip_comp_level 5;
gzip_http_version 1.0;
gzip_min_length 0;
gzip_types text/plain text/html text/css image/x-icon
application/x-javascript;
gzip_vary on;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
[/shell]
3) jetzt gehen wir hin und erstellen im Order /etc/nginx/conf.d/ eine proxy.conf unt tragen die folgenden Werte ein
[shell]
nano /etc/nginx/conf.d/proxy.conf
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 10m;
client_body_buffer_size 128k;
client_header_buffer_size 64k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 16k;
proxy_buffers 32 16k;
proxy_busy_buffers_size 64k;
</code>
4) jetzt muss noch die vhost konfiguration durchgeführt werden, dazu öffnest du in etc/nginx/sites-available/ die default Datei und passt die Werte an.
[/php]
[php]
nano /etc/nginx/sites-available/default
[/php]
[php]
server {
listen 80;
server_name example.com;
access_log /var/www/example.com/log/nginx.access.log;
error_log /var/www/example.com/log/nginx_error.log debug;
#set your default location
location / {
proxy_pass http://127.0.0.1:8080/;
}
#I had a problem accessing phpmyadmin with an Nginx reverse
#proxy without adding this location
location /phpmyadmin {
proxy_pass http://127.0.0.1:8080/phpmyadmin;
allow 1.1.1.1;
deny all;
}
#set your static folder location without the proxy pass so Nginx
#will server those files. We also set expires max to add an
#expires to have the client cache the files. You will
#have to #set a version on your css and js files to prevent
#the user who has cached files from not receiving new versions.
location /static {
root /var/www/example.com/htdocs/;
expires max;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/nginx-default;
}
}
#If you have a subdomain you need to add a new server if you
#want Nginx to server the static files. Our subdomain only
#serves static files so we have not set up a proxy_pass
server {
listen 80;
server_name subdomain.example.com;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/nginx-default;
}
access_log /var/www/subdomain.example.com/log/nginx.access.log;
error_log /var/www/subdomain.example.com/log/nginx.error.log;
index index.html;
location / {
expires max;
root /var/www/subdomain.example.com/htdocs/;
}
}
[/shell]
5) Jetzt muss noch im Apache der Port verändert werden, dazu geht Ihr in die Datei /etc/apache2/ports.conf und ändert den eintrag von Port 80 zu 8080 wie im Beispiel.
[shell]
NameVirtualHost *
Listen 127.0.0.1:8080
[/shell]
6) als Letztes müsst Ihr noch die Dienste neu Starten, und könnt die Einstellung Testen.
[shell]
/etc/init.d/apache2 restart
/etc/init.d/nginx restart
[/shell]
28. Oktober 2010 um 17:52
[...] und schon seit Jahren eingesetzt wird, ist den wenigstens die die Reverse-Proxy-Funktion bekannt. Magento Performance Steigerung AnleitungTags: Magento Cache, Magento Geschwindigkeit, Magento Optimierung, Magento PerformanceHinterlasse [...]
26. September 2011 um 15:05
Hallo Herr Haab,
über Ihren Artikel bin ich auf Sie Aufmerksam geworden.
Ich habe einen Root Server mit Plesk 10.3.1 x64.
Diesen möchte ich ich mit Magento als proxy reverse mit nginx betreiben…. leider klappt es nicht ganz so wie ich es mir vorstelle.
15. Februar 2012 um 11:03
all zu viel wird hier aber aus meiner Sicht nicht gecached
hier fehlen noch Dinge wie:
proxy_cache global;
proxy_cache_valid 200 302 60m;
proxy_cache_valid 404 1m;
proxy_cache_path /var/www/tmpfs/cache/ levels=1:2 keys_zone=global:128M max_size=1G inactive=1440m;
proxy_temp_path /var/www/tmpfs/tmp/;
proxy_cache_key $scheme$host$request_uri;
proxy_cache_use_stale error timeout updating invalid_header http_500 http_502 http_503 http_504;
proxy_cache global;
das tmpfs am Besten gleich im Memory