Setup Nginx, Apache (XAMPP) On Same Server

Overview:

  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:
    F:\xampp\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 / {
                proxy_pass         http://127.0.0.1:8080/;
            }
    		#Adding location for phpmyadmin
    		location /phpmyadmin {
    			proxy_pass         http://127.0.0.1:8080/phpmyadmin;
    			allow 127.0.0.1;
    			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.

Related Posts:

18 thoughts on “Setup Nginx, Apache (XAMPP) On Same Server”

  1. yeah i hve same problem as it gives show up an error as follows nginx: [warn] duplicate MIME type “text/html” in D:\Webserver\xampp\nginx/conf/nginx.conf:19., does everyone know how fix this issue.? regards.

  2. How to know the nginx is running ? i tried these commands nginx -s [ stop | quit | reopen | reload ] but it gives an error as follows nginx: [warn] duplicate MIME type “text/html” in D:\Webserver\xampp\nginx/conf/nginx.conf:19.

    1. Sorry for late reply.

      Take a look at your Nginx config. Try with the following rule:


      location ~* ^.+\.(jpg|jpeg|gif|png|ico|tgz|gz|pdf|rar|bz2|exe|ppt|txt|tar|mid|midi|wav|bmp|rtf) {
      root /folder/to/static/files;
      expires 90d;
      }
      location ~* ^.+\.(css|js)$ {
      root /folder/to/static/files;
      expires 30d;
      }

Leave a Reply

Your email address will not be published. Required fields are marked *