Configure nginx for Windows with Lucee

I am setting up nginx in my development environment. I am using windows 10, Lucee with iis and nodejs with expressjs and iisnode. To replace IIS with nginx, first I downloaded nginx and extracted in C:/nginx. Before we configure nginx, first let’s configure Lucee. I had installed Lucee installer and running on 8888 port. Now add you website entry in engine tag as follow:

Error when loading gists from https://gist.github.com/.

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

Now, create a lucee.conf file and add in C:/nginx/conf folder with following content.

Error when loading gists from https://gist.github.com/.

# 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, we’ll configure nginx so open a file C:/nginx/conf/nginx.conf. Now either remove the existing server block or adjust it according to following:

Error when loading gists from https://gist.github.com/.

server {

    listen 80;
    server_name mysite.local;

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

    include lucee.conf;

}

I am also adding another server block for my node application:

Error when loading gists from https://gist.github.com/.

server {

    listen 8081;
    server_name mynodeapp;

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

    include mynodeapp.conf;

}

mynodeapp.conf file contents are as follow:

Error when loading gists from https://gist.github.com/.

# 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;
}

Okay, required configuration is now completed. Now, you may have IIS is your default http service which starts when your PC starts. We need to stop this to acquire 80 port. Open windows services, and stop World Wide Web Publishing Service. Also make this service manual so that it doesn’t start when your PC starts.

IIS Service

Now, we need to create a service for nginx so that it can be automatically started when PC starts. Visit this stackoverflow page, it will guide you to create windows service wrapper for nginx.

All right, now check out this nginx for windows page, specially known issues and possible future enhancement. Open nginx.conf file and see that they have limited 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 configuration. Now that the required configuration is completed, it’s time to play with nginx to discover best tuning option that suits your web site.