Current time: 05-21-2024, 06:38 PM Hello There, Guest! (LoginRegister)


Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[ERLEDIGT]Nginx Howto, bitte ins Wiki übernehmen...
Author Message
mad max Offline
Junior Member
*

Posts: 47
Joined: Aug 2007
Reputation: 0
Post: #1
[ERLEDIGT]Nginx Howto, bitte ins Wiki übernehmen...
So da mein Howto leider zerschossen wurde mache ich es hier nochmal neu:

Ok jetzt werde ich hier mal ein HOWTO posten, mit dem ich meinen Apache durch den Nginx enlastet habe. Es sei aber angemerkt das dieses HOWTO noch nicht vollständig ausgereift ist. Auf jeden Fall wäre es nett, wenn Leute die sich mit ispCP auskennen an der Fertigstellung/optimierung mitwirken könnten.

Also fange ich mal an:
Ich gehe davon aus das ein fertig eingerichtetes und lauffähiges ispCP System besteht. Als IP verwende ich diese 192.168.1.1 diese muß natürlich bei jedem durch seine eigene ersetzt werden.

Den Apache habe ich erstmal auf Port81 gelegt.Wir editieren /etc/apache2/ports.conf

Code:
Listen 192.168.1.1:81

Sämtliche bereits angelegten virtual hosts müssen ebenfalls angepasst werden. Ich habe die Datei /etc/apache2/sites-available/ispcp.conf mit einem Editor geöffnet. Dort alle angeleten v-hosts geändert dh. Port 80 durch 81 ersetzt.
Hier mal ein kleiner Auszug muß natülich bei jedem schon angelgtem v-host durchgeführt werden.

Code:
# httpd [192.168.1.1] virtual host entry BEGIN.

NameVirtualHost 192.168.1.1:81

# httpd [{DMN_GRP}] dmn group entry BEGIN.
# httpd [{DMN_GRP}] dmn group entry END.
# httpd [waqui2000.halle17.de] dmn group entry BEGIN.

evtl. gibt es ne möglichkeit dieses einfacher zu lösen wenn ja bitte hier posten.

So jetzt installieren wir nginx:

Code:
apt-get install nginx

Jetzt die nginx.conf Datei zu finden etc/nginx/ nginx.conf mit dieser Datei ersetzen:

Code:
user www-data;
worker_processes 2;

error_log  /var/log/nginx/error.log;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
}

http {
    server_names_hash_bucket_size   64;
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    access_log    /var/log/nginx/access.log;

log_format  main  '$remote_addr - $remote_user [$time_local] $status '
                      '"$request" $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "http_x_forwarded_for"';
    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;
    tcp_nodelay        on;
    
    gzip  on;
server {
    listen       192.168.1.1:80 default;
    #server_name  halle17.de;
    access_log /var/log/nginx/default.access.log  main;

    location / {
        proxy_pass http://192.168.1.1:81;
        
   }
}

    include /etc/nginx/proxy.conf;
    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}

Wie ihr seht läuft nginx auf 80 und apache auf 81!!

Dann erstellen wir eine neue Datei Namens"proxy.conf" unter /etc/nginx/
Mit folgendem Inhalt:

Code:
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;
proxy_connect_timeout   90;
proxy_send_timeout      90;
proxy_read_timeout      90;
proxy_buffers           32 4k;

Dieser Teil der oben geposteten nginx.conf

Code:
server {
    listen       XXX.XXX.XXX.XXX:80 default;
    server_name  _;
    access_log /var/log/nginx/default.access.log main;

    location / {
        proxy_pass http://192.168.1.1:81;
        include /etc/nginx/proxy.conf;
   }
}

Wird der default Eintrag dh. ist bei nginx kein v-host angelegt wird gnadenlos alles an den apache weitergeleitet!!

Um jetzt dem nginx mitzuteilen welche v-host auf dem Server laufen. Werden so habe ich es zur Zeit am laufen pro v-host eine Datei angelegt.
In diesem Verzeichniss werden die Dateien erstellt "/etc/nginx/sites-enabled"
Der Name spielt keine rolle um den Überblick zu behalten, habe ich den Domainnamen genommen.
Der Inhalt dieser Datei/en sieht so aus:

Code:
server {
    listen 192.168.1.1:80;
    server_name  www.xxxxxxx.de xxxxxxx.de *.xxxxxxxxx.de;

    location / {
        proxy_pass http://192.168.1.1:81;
        include /etc/nginx/proxy.conf;
    }

    location ~* ^.+.(jpe?g|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|mi​di|wav|bmp|rtf|js|swf|avi|mp3)$ {
        expires 30d;
        root /var/www/xxxxxx/xxxxxx.de/htdocs;
    }
}

Server Name und root muß natürlich angepasst werden!!!

Jetzt starten wir Apache neu:

Code:
/etc/init.d/apache2 restart

Jetzt noch den Nginx starten

Code:
/etc/init.d/nginx start

Code:
/usr/local/nginx/sbin/nginx -c /etc/nginx/nginx.conf

Ein Nginx reload geht so:

Code:
/etc/init.d/nginx restart

Code:
kill -HUP `cat /var/run/nginx.pid`

So weit so gut bis dorthin lief auf anhieb alles Problemlos. Nur mußte ich feststellen das in den Apache Logs falsche ober besser gesagt nur noch die ip 192.168.1.1 geloggt wird und nicht mehr die tatsächliche ip. Aber auch dafür habe ich eine Lösung gefunden.

mod-rpaf war die Lösung

Code:
apt-get libapache2-mod-rpaf

Jetzt mußten nochmal die v-host configs von ispCP editiert werden.
Also nochmal /etc/apache2/sites-available/ispcp.conf mit einem editor geöffnet und bei jedem vhost diesen Teil hinzugefügt:

Code:
RPAFenable On
RPAFsethostname On
RPAFproxy_ips 192.168.1.1

Sieht dann so aus:

Code:
# httpd [192.168.1.1] virtual host entry BEGIN.

NameVirtualHost 192.168.1.1:81



# httpd [{DMN_GRP}] dmn group entry BEGIN.
# httpd [{DMN_GRP}] dmn group entry END.
RPAFenable On
RPAFsethostname On
RPAFproxy_ips 192.168.1.1

<IfModule mod_cband.c>
    <CBandUser waqui2000.halle17.de>
        # CBandUserLimit 0Mi
        # CBandUserScoreboard /var/www/scoreboards/waqui2000.halle17.de
        # CBandUserPeriod 4W
        # CBandUserPeriodSlice 1W
        # CBandUserExceededURL http://xxxxxxxxxxx/errors/bw_exceeded.html
    </CBandUser>
</IfModule>

So das war es alles läuft super schneller und der Serverload ist deutlich geringer geworden.

Um das jetzt weitgehend zu automatisieren dh wenn eine neue Domain angelegt wird habe ich folgende Templates editiert.

/etc/ispcp/apache/parts

-dmn_entry.tpl
-sub_entry.tpl
-vh_entry.tpl


Code:
<VirtualHost {DMN_IP}:81>

    <IfModule suexec_module>
           SuexecUserGroup {SUEXEC_USER} {SUEXEC_GROUP}
    </IfModule>

    ServerAdmin     webmaster@{DMN_NAME}
    DocumentRoot    {WWW_DIR}/{DMN_NAME}/htdocs

    ServerName      {DMN_NAME}
    ServerAlias     www.{DMN_NAME} {DMN_NAME} *.{DMN_NAME}

    Alias /errors   {WWW_DIR}/{DMN_NAME}/errors/

    RedirectMatch permanent ^/ftp([\/]?)        http://{BASE_SERVER_VHOST}/ftp/
    RedirectMatch permanent ^/pma([\/]?)        http://{BASE_SERVER_VHOST}/pma/
    RedirectMatch permanent ^/webmail([\/]?)    http://{BASE_SERVER_VHOST}/webmail/

    ErrorDocument 401 /errors/401.html
    ErrorDocument 403 /errors/403.html
    ErrorDocument 404 /errors/404.html
    ErrorDocument 500 /errors/500.html
    ErrorDocument 503 /errors/503.html

RPAFenable On
RPAFsethostname On
RPAFproxy_ips {DMN_IP}

    <IfModule mod_cband.c>
        CBandUser {DMN_GRP}
    </IfModule>

    # httpd awstats support BEGIN.
    # httpd awstats support END.

    # httpd dmn entry cgi support BEGIN.
    # httpd dmn entry cgi support END.

    <Directory {WWW_DIR}/{DMN_NAME}/htdocs>
        # httpd dmn entry PHP support BEGIN.
        # httpd dmn entry PHP support END.
        Options -Indexes Includes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>

    # httpd dmn entry PHP2 support BEGIN.
    # httpd dmn entry PHP2 support END.

    Include {CUSTOM_SITES_CONFIG_DIR}/{DMN_NAME}.conf

</VirtualHost>

Code:
NameVirtualHost {SUB_IP}:81

# httpd [{DMN_GRP}] dmn group entry BEGIN.
# httpd [{DMN_GRP}] dmn group entry END.

# httpd [{ALS_NAME}] als entry BEGIN.
# httpd [{ALS_NAME}] als entry END.

Code:
<VirtualHost {SUB_IP}:81>

    #
    #User {SUEXEC_USER}
    #Group {SUEXEC_GROUP}
    #

    <IfModule suexec_module>
           SuexecUserGroup {SUEXEC_USER} {SUEXEC_GROUP}
    </IfModule>

    ServerAdmin     webmaster@{DMN_NAME}
    DocumentRoot    {WWW_DIR}/{DMN_NAME}{MOUNT_POINT}/htdocs

    ServerName      {SUB_NAME}
    ServerAlias     www.{SUB_NAME} {SUB_NAME} *.{SUB_NAME}

    Alias /errors {WWW_DIR}/{DMN_NAME}/errors/

    ErrorDocument 401 /errors/401.html
    ErrorDocument 403 /errors/403.html
    ErrorDocument 404 /errors/404.html
    ErrorDocument 500 /errors/500.html
    ErrorDocument 503 /errors/503.html

RPAFenable On
RPAFsethostname On
RPAFproxy_ips {SUB_IP}

    <IfModule mod_cband.c>
        CBandUser {DMN_GRP}
    </IfModule>

    # httpd sub entry cgi support BEGIN.
    # httpd sub entry cgi support END.

    <Directory {WWW_DIR}/{DMN_NAME}{MOUNT_POINT}/htdocs>
        # httpd sub entry PHP support BEGIN.
        # httpd sub entry PHP support END.
        Options -Indexes Includes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>

    # httpd sub entry PHP2 support BEGIN.
    # httpd sub entry PHP2 support END.

    Include {CUSTOM_SITES_CONFIG_DIR}/{SUB_NAME}.conf

</VirtualHost>

Jetzt müßte man es nur noch hinbekommen das auch gleichzeitig hier /etc/nginx/sites-enabled/" eine neue Datei erstellt wird mit dem neuen v-host wie er oben beschrieben ist. Dann bleibt nur noch der reload von nginx damit die neue Datei geladen wird.

Achtung "libapache2-mod-rpaf " gibt es nur für Lenny!! Für alle die Etch verwenden folgt dieser Teil:

Code:
cd /usr/local/src

Code:
wget http://stderr.net/apache/rpaf/download/mod_rpaf-0.6.tar.gz

Code:
tar xzf mod_rpaf-0.6.tar.gz

Code:
cd mod_rpaf-0.6

Compiling rpaf module:

Code:
nano /usr/local/src/mod_rpaf-0.6/makefile

Change APXS=$(shell which apxs) to APXS=/usr/sbin/apxs.

Code:
make rpaf-2.0 && make install-2.0

Diesen Teil natürlich nicht vergessen ist ja ich HOWTO beschrieben:

Code:
RPAFenable On
RPAFsethostname On
RPAFproxy_ips 192.168.1.1


So das ganze läuft jetzt seit dem 15.01.2009 auf meinem Produktivserver ohne Probleme. Allerdings müssen die Änderungen noch per Hand erledigt werden wie zb die V-Host Einträge für den Nginx.

mfg
Mad Max
(This post was last modified: 10-10-2009 12:27 AM by ZooL.)
03-07-2009 11:36 PM
Find all posts by this user Quote this message in a reply
Post Reply 


Messages In This Thread
[ERLEDIGT]Nginx Howto, bitte ins Wiki übernehmen... - mad max - 03-07-2009 11:36 PM

Forum Jump:


User(s) browsing this thread: 1 Guest(s)