How To Configure nginx for Windows with Lucee?

For the configuring nginx for Windows in the software development process in Lucee/ColdFusion technology, which runs on Windows 10. In this environment, Using Lucee with IIS and Node.js with Express.js and iisnode. To replace IIS with nginx, in that process first downloaded nginx and developed it to C:/nginx. Before configuring nginx, let’s set up Lucee. After installing Lucee it’s running on port 8888. Now, add your website entry in the engine tag as follows:




<!-- ADD NEW HOSTS HERE -->
<!-- VIRTUAL HOST -->
<Host name="mysite.local" appBase="webapps">
<Context path="" docBase="C:/mysite.local" />
</Host>

 

After that, create a lucee.conf file and add it in C:/nginx/conf folder with the following content.



# Main Lucee proxy handler
location ~ \.(cfm|cfml|cfc|jsp|cfr)(.*)$ {
    proxy_pass http://127.0.0.1:8888;
    proxy_redirect off;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-Host $host;
    proxy_set_header X-Forwarded-Server $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Real-IP $remote_addr;
}

#This is for static content
location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
    access_log off;
    gzip_static on;
    expires 1w;
    add_header Cache-Control public;
    add_header ETag "";
}

 

Now, the second process is to configure nginx. Open the file C:/nginx/conf/nginx.conf. Either remove the existing server block or adjust it according to the following:



server {

    listen 80;
    server_name mysite.local;

    root C:/mysite.local;
    index index.html index.htm index.cfm;

    include lucee.conf;

}

 

Additionally, add another server block for the Node.js application: 



server {

    listen 8081;
    server_name mynodeapp;

    root C:/mynodeapp;
    index index.html index.htm;

    include mynodeapp.conf;

}

 

The contents of mynodeapp.conf file is as follows:



# Main node proxy handler
location / {
    proxy_pass http://127.0.0.1:3000;
    proxy_redirect off;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-Host $host;
    proxy_set_header X-Forwarded-Server $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Real-IP $remote_addr;
}

 

With the required configurations completed, we need to stop the IIS service to acquire port 80. Open Windows services and stop the World Wide Web Publishing Service. It is necessary to set it to manual, so it doesn’t start automatically.

what is iis server
Now, in the third step, we’ll build a service for nginx so that it starts automatically with the PC. Refer to this Stack Overflow page for guidance on creating a Windows service wrapper for nginx. 

Check out the nginx for Windows page for known issues and possible future enhancements. Open the nginx.conf file and note that the worker_processes  to 1. I tested my website with jMeter, and found that it gives poor performance than IIS. I increased it to 1024, and now it gives good performance than IIS.

I hope this post helps you. Let me if you find any issues with the configuration. Now that the required configuration is completed, it’s time to play with nginx to discover the best tuning option that suits your website.

how can we help you?

Contact us at the Consulting WP office nearest to you or submit a business inquiry online.

Get technology solution for your business need