• 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

This Article Has Been Shared 999 Times!

Facebook Twitter Pinterest
Abhishek Ghosh

About Abhishek Ghosh

Abhishek Ghosh is a Businessman, Orthopaedic 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 PHP5-FPM WordPress : Major Tweaks

    Here is a Short Yet More Than Enough Guide For the Most To Tweak Nginx PHP5-FPM WordPress Setup Running on Ubuntu 14.04 on Rackspace Cloud Server.

  • HHVM WordPress (Nginx Ubuntu Server) Tweaks

    Here are some special HHVM Wordpress (Nginx Ubuntu Server) Tweaks for Page Speed optimization, Compatibility of WordPress Themes and Plugins.

  • Zend Opcache Optimization for Nginx Ubuntu (HP Cloud)

    Here is Full Guide to Zend Opcache Optimization for Nginx PHP5-FPM for Ubuntu Server Running on HP Cloud. We Suggest to Use Zend Opcache over APC.

  • Nginx Cache Purge Module For fastcgi_cache WordPress

    Nginx Plus by Default Supports Cache Purging. Nginx Cache Purge Module For fastcgi_cache Exists Can Be Used For Community Edition of Nginx.

  • Nginx WWW to No WWW & HTTP to HTTPS

    Basic, Yet Many New Users Fight With Nginx WWW to No WWW & HTTP to HTTPS Rules on Cloud Server Instance Running Debian/Ubuntu GNU/Linux.

Additionally, 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

You can subscribe to our Free Once a Day, Regular Newsletter by clicking the subscribe button below.

Click To Subscribe

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 (21K Followers)
  • Twitter (5.3k 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

  • Basics on Python Tornado (web server) March 8, 2021
  • What You Need to Know About Hybrid Mobile App Development March 6, 2021
  • Why Not to Use Your Host for Email Marketing March 5, 2021
  • What You Need to Know About the Microservices March 4, 2021
  • Fix Missing/Bad FileProvider for Freshchat (Android error code 354) March 3, 2021

 

About This Article

Cite this article as: Abhishek Ghosh, "Nginx Configuration With include Directive For WordPress," in The Customize Windows, July 28, 2015, March 8, 2021, https://thecustomizewindows.com/2015/07/nginx-configuration-with-include-directive-for-wordpress/.

Source:The Customize Windows, JiMA.in

 

This website uses cookies. If you do not want to allow us to use cookies and/or non-personalized Ads, kindly clear browser cookies after closing this webpage.

Read Cookie Policy.

PC users can consult Corrine Chorney for Security.

Want to know more about us? Read Notability and Mentions & Our Setup.

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

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