• Home
  • Archive
  • Tools
  • Contact Us

The Customize Windows

Technology Journal

  • Cloud Computing
  • Computer
  • Digital Photography
  • Windows 7
  • Archive
  • Cloud Computing
  • Virtualization
  • Computer and Internet
  • Digital Photography
  • Android
  • Sysadmin
  • Electronics
  • Big Data
  • Virtualization
  • Downloads
  • Web Development
  • Apple
  • Android
Advertisement
You are here:Home » Nginx Configuration With include Directive For WordPress

By Abhishek Ghosh July 28, 2015 10:48 pm Updated on July 28, 2015

Nginx Configuration With include Directive For WordPress

Advertisement

Specially for HSTS WordPress configuration, the configuration file which is, by default /etc/nginx/sites-available/default gets quite bigger. Nginx Configuration With include Directive Can Make the default of nginx.conf file less bloated specially for WordPress W3C like plugins. There are some stuffs to keep in mind for this work.

 

What To Remember For Using Nginx Configuration With include Directive

 

Too much include can make the front end slower. It becomes like, go and read from /etc/nginx/sites-available/default, then go to /etc/nginx/w3c.conf (example); if file ownership and permission is right, then read it, else print error. It is very minute, sometimes invisible change for using too many includes, but logically it can happen when the memory is at margin or server load is higher.

In other words, we will ONLY use the include directive for adding the extras. There is other advantage specially for WordPress W3C Plugin. If we place the W3C settings specific file at location which is readable and writable to W3C, if the location of configuration is corrected from W3C Plugin’s dashboard, it becomes “automatic” for the changes. Same goes for WordPress SEO like common plugins.

Advertisement

---

We can not include the major directions like :

Vim
1
2
3
4
5
6
7
8
9
  server {
    listen       80;
    server_name  jima.in;
    access_log   logs/jima.access.log  main;
    location ~ ^/(images|javascript|js|css|flash|media|static)/  {
      root    /var/www/virtual/jima/htdocs;
      expires 30d;
    }

The nginx.conf file by default includes /etc/nginx/conf.d/ directory. If we place the conf files there, we actually need no separate addition of one line on /etc/nginx/sites-available/default but it probably will be not writeable by PHP (or rather WordPress plugins) in a secured setup.

It is not a great idea to place files in /usr/share/nginx/html (default public root location) or equivalent publicly accessible location.

 

Nginx Configuration With include Directive

 

We have a NGINX configuration as example in GitHub. If you see the default file there, it is hugely big. It is difficult to find a line and manage. Line number 209 to 342 is of WordPress W3C Plugin. You can see this gist here.

We could name it as w3c instead of w3c.conf. If we put that file in /etc/nginx/conf.d/ location, nginx.conf will pick it up without doing anything :

Vim
1
include /etc/nginx/conf.d/*.conf;

In other words, in that case of placing in /etc/nginx/conf.d/ location, we have no work with /etc/nginx/nginx.conf or /etc/nginx/sites-available/default like file. Simply running the config test ( nginx -t ) and restarting nginx should work fine.

BUT, that can get loaded prior to a direction we wanted. Instead, exactly like the SSL certs, we will create a separate directory and chown, chmod it for reading :

Vim
1
2
3
4
mkdir -p /var/nginx/myconfig
sudo chown www-data:nginx /var/nginx/myconfig -R
sudo chmod g+w /var/nginx/myconfig -R
nano /var/nginx/myconfig/w3c.conf

Now, in our example, we are picking up the lines from /etc/nginx/sites-available/default file counting number 209 to 342. We have to vanish the lines first there. Then on line number 209, we will add :

/etc/nginx/sites-available/default
Vim
1
include /var/nginx/myconfig/w3c.conf;

If it throws error after running the config test ( nginx -t ), we will comment the line and add the line within active server block :

Vim
1
2
3
4
5
server {
  listen 443 default spdy;
  server_name thecustomizewindows.com;
include /var/nginx/myconfig/w3c.conf;
...

Nginx Configuration With include Directive For WordPress

 

Nginx Configuration With include Directive Throwing Errors

 

There can never be any error if you follow this method. Nginx is not a herbal product that there will be no logic, most common reason of getting error is too many commented out lines. Nano is a dangerous text editor, if you do not know vim at all, we will suggest to learn vi a bit.

One day I casually opened a XML file of a git (of our company’s one software under development) with nano and nano added line breaks on each line. If it was nginx, the situation became :

Vim
1
2
include
/var/nginx/myconfig/w3c.conf;

Now, obviously nginx will read the empty include first and throw error. It is not very easy to locate such line break on server from SSH and use sed and/or tr to remove the line breaks. Always, when a thing is working, take multiple backups in multiple ways first.

Tagged With nginx include , nginx include file , nginx windows include , nginx includes , nginx include conf , nginx config include ssl , nginx include config , nginx include directive , ngix include , nginx include server directive
Facebook Twitter Pinterest

Abhishek Ghosh

About Abhishek Ghosh

Abhishek Ghosh is a Businessman, Surgeon, Author and Blogger. You can keep touch with him on Twitter - @AbhishekCTRL.

Here’s what we’ve got for you which might like :

Articles Related to Nginx Configuration With include Directive For WordPress

  • Nginx WordPress Installation Guide (All Steps)

    This is a Full Nginx WordPress Installation Guide With All the Steps, Including Some Optimization and Setup Which is Compatible With WordPress DOT ORG Example Settings For Nginx.

  • Changing Data With cURL for OpenStack Swift (HP Cloud CDN)

    Changing Data With cURL For Object is Quite Easy in OpenStack Swift. Here Are Examples With HP Cloud CDN To Make it Clear. Official Examples Are Bad.

  • Steps To Install Nginx Plus on Ubuntu Server (HP Cloud)

    Here Are the Steps To Install Nginx Plus on Ubuntu Server Running on HP Cloud. Nginx Plus is the Paid Version of Nginx with Extra Features.

  • WordPress Multisite on Nginx on Ubuntu 14.04 on HP Cloud

    Here is a Step by Step Guide on Setting Up WordPress Multisite on Nginx on Ubuntu 14.04 on HP Cloud with All Commands and the Configuration.

performing a search on this website can help you. Also, we have YouTube Videos.

Take The Conversation Further ...

We'd love to know your thoughts on this article.
Meet the Author over on Twitter to join the conversation right now!

If you want to Advertise on our Article or want a Sponsored Article, you are invited to Contact us.

Contact Us

Subscribe To Our Free Newsletter

Get new posts by email:

Please Confirm the Subscription When Approval Email Will Arrive in Your Email Inbox as Second Step.

Search this website…

 

Popular Articles

Our Homepage is best place to find popular articles!

Here Are Some Good to Read Articles :

  • Cloud Computing Service Models
  • What is Cloud Computing?
  • Cloud Computing and Social Networks in Mobile Space
  • ARM Processor Architecture
  • What Camera Mode to Choose
  • Indispensable MySQL queries for custom fields in WordPress
  • Windows 7 Speech Recognition Scripting Related Tutorials

Social Networks

  • Pinterest (24.3K Followers)
  • Twitter (5.8k Followers)
  • Facebook (5.7k Followers)
  • LinkedIn (3.7k Followers)
  • YouTube (1.3k Followers)
  • GitHub (Repository)
  • GitHub (Gists)
Looking to publish sponsored article on our website?

Contact us

Recent Posts

  • Market Segmentation in BriefSeptember 20, 2023
  • What is Booting?September 18, 2023
  • What is ncurses?September 16, 2023
  • What is JTAG in Electronics?September 15, 2023
  • iPhone 15 Pro Max Vs Samsung Galaxy S22/S23 UltraSeptember 14, 2023
PC users can consult Corrine Chorney for Security.

Want to know more about us?

Read Notability and Mentions & Our Setup.

Copyright © 2023 - The Customize Windows | dESIGNed by The Customize Windows

Copyright  · Privacy Policy  · Advertising Policy  · Terms of Service  · Refund Policy