How to: Use SysCP Panel with Nginx + Apache2 * Update 2

Please make sure your familiar with SysCP, Apache and your Server.
Since i’m using SysCP to manage my Vhosts i created a script to do the Nginx SiteConfiguration.

Nginx Configuration’s

/etc/nginx/syscp_sites.conf – This file will be dynamicaly generated.

/etc/nginx/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;
proxy_connect_timeout   90;
proxy_send_timeout      90;
proxy_read_timeout      90;
proxy_buffers           32 4

/etc/nginx/nginx.conf

user www-data;
worker_processes 4;
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;
  include /etc/nginx/proxy.conf;
  include /etc/nginx/syscp_sites.conf;
  sendfile on;  keepalive_timeout 1;
  tcp_nodelay on;
  gzip on;
  # All unkown Hosts will be put through to Apache.
  server {
    listen 80;
    server_name _;
    location / {
      proxy_pass http://127.0.0.1:8080;
    }
  }
}

Apache Configuration

Change the Logformat to report the correct IP, otherwise it would only state “127.0.0.1″.

LogFormat "%{X-Real-IP}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%{X-Real-IP}i %l %u %t \"%r\" %>s %b" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent

SysCP Configuration

Next Add a new IP/Port (127.0.0.1:8080) inside your AdminPanel, and Change all your Domains to the new IP/Port, and make it your default IP/Port. There is no need to delete your old IP.

Create an restart Script for SysCP, and set it in your SysCP Configuration.

/etc/init.d/apachenginxrestart

#!/bin/bash
/etc/nginx/nginx_syscp.sh
/usr/sbin/apache2ctl graceful
/etc/init.d/nginx restart 1>/dev/null
/etc/init.d/nginx start 1>/dev/null

Nginx Config Generator

Now we need the Script to create the vhosts mentioned before.
See Attachment.

Make sure you “chmod +x” the script.
The Result will look like:
/etc/nginx/syscp_sites.conf

server {
   listen 80;
   access_log /var/customers/logs/cust-access.log;
   server_name customer.com www.customer.com;
   root /var/customers/webs/customer/;
   location ~* ^/var/customers/webs/customer/webalizer// {
    auth_basic "Restricted";
    auth_basic_user_file /etc/apache2/htpasswds/1-1.htpasswd;
  }
  location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js|mov)$ {
    if (!-f $request_filename) {
      proxy_pass http://127.0.0.1:8080;
      break;
    }
  }
  location / {
    proxy_pass http://127.0.0.1:8080;
  }
}

Run /etc/init.d/apachenginxrestart and you are set.

Links and Reference

Update

  • Fixed a Bug with Alias Domains

Attachment: nginx_syscp.sh

One Comment

  1. [...] Um auf einem SysCP System nginex zu betreiben, gibt es eine hervorragende Anleitung unter http://wp.dead.at/2008/08/how-use-syscp-panel-nginx-apache2-update-2. [...]

Leave a Reply