I'll post how I did it:
Since your box is ubuntu based, which is debian based I assume you can use apt.
"NGINX™ is a high performance edge web server with the lowest memory footprint and the key features to build modern and efficient web infrastructure"
I use it in production on all servers where a webserver is needed.
It's especially good in serving static content and has lots of caching options.
My switch from apache (about 1,5 year ago) took me about 15 minutes.
If you still want/need apache it's fairly easy do a setup using exactly the technique described below. The only thing changed would be apache's listening port.
First we install nginx
http://nginx.org/
(alternatively: use dotdeb.org repository for younger releases)
Code: Select all
$ apt-get update && apt-get install nginx
If you do not already run a webserver you don't need to do the following.
Assuming you have apache:
Code: Select all
$ /etc/init.d/apache2 stop
$ nano /etc/apache2/ports.conf
This will show you your listening port for apache, something like:
Code: Select all
# If you just change the port or add more ports here, you will likely also
# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default
# This is also true if you have upgraded from before 2.2.9-3 (i.e. from
# Debian etch). See /usr/share/doc/apache2.2-common/NEWS.Debian.gz and
# README.Debian.gz
NameVirtualHost *:80
Listen 80
<IfModule mod_ssl.c>
# If you add NameVirtualHost *:443 here, you will also have to change
# the VirtualHost statement in /etc/apache2/sites-available/default-ssl
# to <VirtualHost *:443>
# Server Name Indication for SSL named virtual hosts is currently not
# supported by MSIE on Windows XP.
Listen 443
</IfModule>
<IfModule mod_gnutls.c>
Listen 443
</IfModule>
Change the port into something logical:
Save the document (nano: control+o, enter) and close it (nano: control+x)
You'll need to edit the ports of the viritual hosts that you already have.
Use this command to view enabled sites:
You should change every line like: <VirtualHost *:80> into the port you used above: <VirtualHost *:81>
restart apache and confirm everything is working by visiting your site on the new port (
http://localhost:81 ).
continue here of you did not have a webserver.
Adding proxies to nginx:
open the default site:
Code: Select all
$ nano /etc/nginx/sites/enabled/default
This will look something like:
Code: Select all
server {
#listen 80; ## listen for ipv4; this line is default and implied
#listen [::]:80 default ipv6only=on; ## listen for ipv6
root /usr/share/nginx/www;
index index.html index.htm;
# Make site accessible from http://localhost/
server_name localhost;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to index.html
try_files $uri $uri/ /index.html;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
location /doc/ {
alias /usr/share/doc/;
autoindex on;
allow 127.0.0.1;
deny all;
}
# Only for nginx-naxsi : process denied requests
#location /RequestDenied {
# For example, return an error code
#return 418;
#}
#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 /usr/share/nginx/www;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# fastcgi_split_path_info ^(.+\.php)(/.+)$;
# # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
#
# # With php5-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# # With php5-fpm:
# fastcgi_pass unix:/var/run/php5-fpm.sock;
# fastcgi_index index.php;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
Now I'll assume you'll just use it as proxy (since I might have already gone out of scope here hehehe)
Edit it to fit something like this:
Code: Select all
server {
listen 80;
root /var/www/public;
index index.html;
server_name sab.yourdomain.com;
location / {
resolver 8.8.8.8;
proxy_buffering off;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://127.0.0.1:8080;
}
}
server {
listen 80;
root /var/www/public;
index index.html;
server_name sick.yourdomain.com;
location / {
resolver 8.8.8.8;
proxy_buffering off;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://127.0.0.1:8081;
}
}
resolver: this is needed to resolve domain names, normally used if you use domain names as proxy pass address. it should work without.
I've used google's dns server (8.8.8.

here.
proxy pass: the address / port of the webserver you're trying to reach.
You can have multiple server blocks in 1 file.
Alternatively also add a proxy pass to your apache server on the port you configured it for.
Save the file and restart nginx
The last thing to do is actually add the dns records to your zone.
you can either do the quick and dirty fix:
Use an asterix to have any unspecified subdomain forwarded to your ip:
*.yourdomain.com A yourip
or make nice seperate entries:
sab.yourdomain.com A yourip
sick.yourdomain.com A yourip
Thats it.
Note:
It is highly unlikely that you'll break your system using this small tut. Nevertheless I won't accept any form of responsibility.
If you need help or run into problems I'd be happy to help though.