My Blog
Scroll down to discover

Setup Nginx on Apache (XAMPP) On Same Server

November 12, 2013Category : IT & Network

Step by Step


  1. Nginx port 80
  2. Apache port 8080
  3. Nginx and Apache share root directory (F:\xampp\htdocs)
  4. Nginx catch request as front-end and proxy dynamic content (PHP) to Apache which will be running in the back-end.
  5. Install WordPress, Joomla and Drupal for development on localhost and work perfectly.
  6. Setup on Windows XP.

Things you need:

  1. nginx/Windows-1.1.5
  2. XAMPP 1.7.7

The Setups:

  1. Install XAMPP 1.7.7. For the purpose of this article, I put on F:\xampp
  2. Open F:\xampp\apache\conf\httpd.conf and change default listen to 8080:
    Listen 8080
  3. Save and start Apache from XAMPP Control Panel Application.
  4. Unzip the nginx-1.1.5 to XAMPP directory and rename to nginx:
  5. Open F:\xampp\nginx\conf\nginx.conf and follow this setting:
    worker_processes  1;
    error_log  logs/error.log;
    events {
        worker_connections  1024;
    http {
        include		mime.types;
    	include    	proxy.conf;
        default_type  application/octet-stream;
        sendfile        on;
        keepalive_timeout  65;
        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;
        server {
            listen       80;
            server_name  localhost;
    		location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|pdf|txt|tar|wav|bmp|rtf|js|flv|swf|html|htm)$
    			#root   html;
    			root   F:/xampp/htdocs;
    			expires max;
    		#set default location
            location / {
    		#Adding location for phpmyadmin
    		location /phpmyadmin {
    			deny all;
            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   html;
    	#Optional. If you have a subdomain to serves static files so we have not set up a proxy_pass.
    	server {
    		listen 80;
    		server_name s0.jpa.gov.my s1.jpa.gov.my; # Alternately: _
    		error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
    		access_log logs/static.access.log;
    		error_log logs/static.error.log;
    		index index.html;
    		location / {
    			expires     max;
    			root   F:/xampp/htdocs;
  6. Create the file proxy.conf in the F:\xampp\nginx\conf\ folder (same directory with nginx.conf) with the following contents:
    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;
  7. Double click Nginx.exe on F:\xampp\nginx folder to start Nginx server.

Go to browser and enter http://localhost/. if you see XAMPP default home and don’t see any errors that is a good start. You can delete subdomain part on ingix.conf if you like. This method I used to setup POC for http://www.jpa.gov.my web server with Joomla, WordPress and PhpMyAdmin already installed and worl perfectly!. Hope this can help and if you need any support just leave a comment and we’ll try and help you.

© Oliver / All rights reserved.
To top