Search
Categories
Setup Nginx on Apache (XAMPP) On Same Server
Step by Step
Overview:
- Nginx port 80
- Apache port 8080
- Nginx and Apache share root directory (F:\xampp\htdocs)
- Nginx catch request as front-end and proxy dynamic content (PHP) to Apache which will be running in the back-end.
- Install WordPress, Joomla and Drupal for development on localhost and work perfectly.
- Setup on Windows XP.
Things you need:
The Setups:
- Install XAMPP 1.7.7. For the purpose of this article, I put on F:\xampp
- Open F:\xampp\apache\conf\httpd.conf and change default listen to 8080:
Listen 8080
- Save and start Apache from XAMPP Control Panel Application.
- Unzip the nginx-1.1.5 to XAMPP directory and rename to nginx:
F:\xampp\nginx
- 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; } } }
- 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;
- 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.
01.