<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/">
	<channel>
		<title><![CDATA[Admin Reference - All Forums]]></title>
		<link>http://www.adminreference.com/</link>
		<description><![CDATA[Admin Reference - http://www.adminreference.com]]></description>
		<pubDate>Wed, 22 Feb 2012 22:06:08 +0000</pubDate>
		<generator>MyBB</generator>
		<item>
			<title><![CDATA[Useful (And Uncommon) Commands]]></title>
			<link>http://www.adminreference.com/showthread.php?tid=12</link>
			<pubDate>Fri, 25 Nov 2011 04:10:43 +0000</pubDate>
			<guid isPermaLink="false">http://www.adminreference.com/showthread.php?tid=12</guid>
			<description><![CDATA[I have a feeling ill be the only one posting in here for a while.<br />
<br />
Soo basically, post any useful commands you find.. List the operating system(s), the command, what it does, and an example. Ill start<br />
<br />
<span style="font-weight: bold;">Command</span>: aspell<br />
<span style="font-weight: bold;">Operating System(s)</span>: Linux/Unix<br />
<span style="font-weight: bold;">Description</span>: Command line spell checker.<br />
<span style="font-weight: bold;">Example</span>:<br />
<blockquote><cite>Quote:</cite>[root@svr1 ~]# cat test.txt<br />
Welcome to Admin Reference! This is a mispeled word<br />
[root@svr1 ~]# aspell -c test.txt<br />
[root@svr1 ~]# cat test.txt<br />
Welcome to Admin Reference! This is a misspelled word</blockquote>
<br />
Here's what the interface looks like<br />
<div class="codeblock">
<div class="title">Code:<br />
</div><div class="body" dir="ltr"><code>Welcome to Admin Reference! This is a mispeled word<br />
<br />
1) misspelled&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 6) misruled<br />
2) misapplied&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 7) mislead<br />
3) misled&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 8) spelled<br />
4) dispelled&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;9) spieled<br />
5) misfiled&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0) misplaced<br />
i) Ignore&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; I) Ignore all<br />
r) Replace&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;R) Replace all<br />
a) Add&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;l) Add Lower<br />
b) Abort&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x) Exit<br />
<br />
&gt;</code></div></div>
]]></description>
			<content:encoded><![CDATA[I have a feeling ill be the only one posting in here for a while.<br />
<br />
Soo basically, post any useful commands you find.. List the operating system(s), the command, what it does, and an example. Ill start<br />
<br />
<span style="font-weight: bold;">Command</span>: aspell<br />
<span style="font-weight: bold;">Operating System(s)</span>: Linux/Unix<br />
<span style="font-weight: bold;">Description</span>: Command line spell checker.<br />
<span style="font-weight: bold;">Example</span>:<br />
<blockquote><cite>Quote:</cite>[root@svr1 ~]# cat test.txt<br />
Welcome to Admin Reference! This is a mispeled word<br />
[root@svr1 ~]# aspell -c test.txt<br />
[root@svr1 ~]# cat test.txt<br />
Welcome to Admin Reference! This is a misspelled word</blockquote>
<br />
Here's what the interface looks like<br />
<div class="codeblock">
<div class="title">Code:<br />
</div><div class="body" dir="ltr"><code>Welcome to Admin Reference! This is a mispeled word<br />
<br />
1) misspelled&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 6) misruled<br />
2) misapplied&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 7) mislead<br />
3) misled&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 8) spelled<br />
4) dispelled&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;9) spieled<br />
5) misfiled&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0) misplaced<br />
i) Ignore&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; I) Ignore all<br />
r) Replace&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;R) Replace all<br />
a) Add&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;l) Add Lower<br />
b) Abort&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x) Exit<br />
<br />
&gt;</code></div></div>
]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Welcome back to AR!]]></title>
			<link>http://www.adminreference.com/showthread.php?tid=11</link>
			<pubDate>Mon, 21 Nov 2011 14:35:39 +0000</pubDate>
			<guid isPermaLink="false">http://www.adminreference.com/showthread.php?tid=11</guid>
			<description><![CDATA[Hey guys,<br />
<br />
After many months of being down we are finally back up and rocking. We ran into a few snags here and there and decided to have a nice clean, and fresh start. There have been a few people who asked Justin and Myself why we decided to start a forum, and the answer is quite simple. When we're working day to day and learning new things we typically scatter our notes and guides all throughout our computers, external drives and various notes websites and really wanted a general location to put our guides so not only do we have a single place to go to, to see them, but also to share our knowledge with those who are in need.<br />
<br />
We also love to help out newcomers to various technologies that we know, and even though we are far from being experts in certain fields we definitely believe that we can help out and guide those in the right direction and I feel the community that we can build here will be amazingly helpful.<br />
<br />
We have many things planned for here, and we hope you would like to join us on our journey and perhaps we all can share our knowledge with each other.<br />
<br />
Once again, welcome to the new and improved Admin Reference forums.]]></description>
			<content:encoded><![CDATA[Hey guys,<br />
<br />
After many months of being down we are finally back up and rocking. We ran into a few snags here and there and decided to have a nice clean, and fresh start. There have been a few people who asked Justin and Myself why we decided to start a forum, and the answer is quite simple. When we're working day to day and learning new things we typically scatter our notes and guides all throughout our computers, external drives and various notes websites and really wanted a general location to put our guides so not only do we have a single place to go to, to see them, but also to share our knowledge with those who are in need.<br />
<br />
We also love to help out newcomers to various technologies that we know, and even though we are far from being experts in certain fields we definitely believe that we can help out and guide those in the right direction and I feel the community that we can build here will be amazingly helpful.<br />
<br />
We have many things planned for here, and we hope you would like to join us on our journey and perhaps we all can share our knowledge with each other.<br />
<br />
Once again, welcome to the new and improved Admin Reference forums.]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Beginner's Guide to Git]]></title>
			<link>http://www.adminreference.com/showthread.php?tid=10</link>
			<pubDate>Mon, 21 Nov 2011 14:28:00 +0000</pubDate>
			<guid isPermaLink="false">http://www.adminreference.com/showthread.php?tid=10</guid>
			<description><![CDATA[If you're not using Git currently, then you definitely are living in the old days and it's time for you to grow up. Git was created by Linus Torvalds and was done so because of the lack of satisfaction with the other solutions that are in place (CVS, Subversion). With Git, it has a revision control system that can easily help you revert your code back to a pervious version at a previous time, thus saving you the time of having to back up or store multiple copies of your code in separate places. Along with it, it tracks each change that is done your code and files.<br />
<br />
<span style="font-size: large;"><span style="font-weight: bold;">1) Installing Git</span></span><br />
<br />
Installing Git should be very easy to do, and it all depends on the distro that you're using, but typically all distros have git in their standard repositiories.<br />
<br />
Here is how you can install it on these two popular distros:<br />
<br />
<span style="font-weight: bold;">CentOS</span><br />
<div class="codeblock">
<div class="title">Code:<br />
</div><div class="body" dir="ltr"><code>sudo yum install git</code></div></div>
<br />
<span style="font-weight: bold;">Ubuntu</span><br />
<div class="codeblock">
<div class="title">Code:<br />
</div><div class="body" dir="ltr"><code>sudo apt-get install git-core</code></div></div>
<br />
Or if you would prefer, you can manually download it and install it from <a href="http://git-scm.com/download" target="_blank">here</a><br />
<br />
<span style="font-size: large;"><span style="font-weight: bold;">2) Creating a Repository</span></span><br />
Once you have installed Git on your system, you then can create a local Git repository, and use that or like I will show you in this tutorial, you can use an external server to store your code. In this tutorial we will use github.com to store our code, and they will do it for free if you are an open source project. <br />
<br />
So I would head over to github, and then once you're logged in you will want to create a repository and name it whatever you would like and then after that this is all you would do (which these instructions are given to you on github as well). After you have created your repository, you will want to add your SSH Public Key to allow you to push and pull without a password, this is optional of course. To do this you would navigate to Account Settings --&gt; SSH Public Keys.<br />
<br />
Then you will need to set up and configure git to use your username and email address so you would do:<br />
<br />
<div class="codeblock">
<div class="title">Code:<br />
</div><div class="body" dir="ltr"><code>git config --global user.name "Your Name"<br />
git config --global user.email youremail@domain.com</code></div></div>
<br />
Then you will want to create the directory to set up your repository, in this case my repository name is "artest" so I will do the following:<br />
<br />
<div class="codeblock">
<div class="title">Code:<br />
</div><div class="body" dir="ltr"><code>mkdir artest<br />
cd artest<br />
git init<br />
touch README<br />
git add README<br />
git commit -m 'first commit'<br />
git remote add origin git@github.com:&lt;USERNAME&gt;/&lt;REPONAME&gt;.git<br />
git push -u origin master</code></div></div>
<br />
Then you're done setting up the repository. You can skip all of the above if you are just going to pull and contribute to an existing repository, and here is how you can do that.<br />
<br />
<span style="font-size: large;"><span style="font-weight: bold;">3) Using Git</span></span><br />
<br />
<span style="font-size: medium;"><span style="font-weight: bold;">Grabbing the files</span></span><br />
If you don't already have the files on your local machine, you can grab them by using the following:<br />
<br />
<div class="codeblock">
<div class="title">Code:<br />
</div><div class="body" dir="ltr"><code>git clone (URL, ie git://github.com/github/linux-2.6.git)</code></div></div>
<br />
<br />
Then you can make your modifications to the file(s), and then to apply your changes to the repository (if you have write access). After you modify a file you will need to add that file to be committed.<br />
<br />
Add a file/directory to be committed:<br />
<br />
<div class="codeblock">
<div class="title">Code:<br />
</div><div class="body" dir="ltr"><code>git add &lt;file/directory&gt;</code></div></div>
<br />
Then once you have added all of your files you can do:<br />
<br />
<div class="codeblock">
<div class="title">Code:<br />
</div><div class="body" dir="ltr"><code>git commit -m "My message letting me know the changes that I have done"</code></div></div>
<br />
Once you've added the file(s) or directories and committed them to your local repo, you then can push your changes to the external server with:<br />
<br />
<div class="codeblock">
<div class="title">Code:<br />
</div><div class="body" dir="ltr"><code>git push</code></div></div>
<br />
Other useful commands<br />
<br />
A command that I personally use frequently is:<br />
<br />
<div class="codeblock">
<div class="title">Code:<br />
</div><div class="body" dir="ltr"><code>git status</code></div></div>
<br />
This will provide you a list of files that have been modified and tell you if they have been added to your commits or not. This quickly lets me know what I am missing or what is actually going to be pushed when I do it.<br />
<br />
<br />
Here is a great website as well to get more commands if you wish to dig in further.<br />
<br />
<blockquote><cite>Quote:</cite><a href="http://gitref.org" target="_blank">http://gitref.org</a></blockquote>
<br />
I'll continue to update this, so keep checking back!]]></description>
			<content:encoded><![CDATA[If you're not using Git currently, then you definitely are living in the old days and it's time for you to grow up. Git was created by Linus Torvalds and was done so because of the lack of satisfaction with the other solutions that are in place (CVS, Subversion). With Git, it has a revision control system that can easily help you revert your code back to a pervious version at a previous time, thus saving you the time of having to back up or store multiple copies of your code in separate places. Along with it, it tracks each change that is done your code and files.<br />
<br />
<span style="font-size: large;"><span style="font-weight: bold;">1) Installing Git</span></span><br />
<br />
Installing Git should be very easy to do, and it all depends on the distro that you're using, but typically all distros have git in their standard repositiories.<br />
<br />
Here is how you can install it on these two popular distros:<br />
<br />
<span style="font-weight: bold;">CentOS</span><br />
<div class="codeblock">
<div class="title">Code:<br />
</div><div class="body" dir="ltr"><code>sudo yum install git</code></div></div>
<br />
<span style="font-weight: bold;">Ubuntu</span><br />
<div class="codeblock">
<div class="title">Code:<br />
</div><div class="body" dir="ltr"><code>sudo apt-get install git-core</code></div></div>
<br />
Or if you would prefer, you can manually download it and install it from <a href="http://git-scm.com/download" target="_blank">here</a><br />
<br />
<span style="font-size: large;"><span style="font-weight: bold;">2) Creating a Repository</span></span><br />
Once you have installed Git on your system, you then can create a local Git repository, and use that or like I will show you in this tutorial, you can use an external server to store your code. In this tutorial we will use github.com to store our code, and they will do it for free if you are an open source project. <br />
<br />
So I would head over to github, and then once you're logged in you will want to create a repository and name it whatever you would like and then after that this is all you would do (which these instructions are given to you on github as well). After you have created your repository, you will want to add your SSH Public Key to allow you to push and pull without a password, this is optional of course. To do this you would navigate to Account Settings --&gt; SSH Public Keys.<br />
<br />
Then you will need to set up and configure git to use your username and email address so you would do:<br />
<br />
<div class="codeblock">
<div class="title">Code:<br />
</div><div class="body" dir="ltr"><code>git config --global user.name "Your Name"<br />
git config --global user.email youremail@domain.com</code></div></div>
<br />
Then you will want to create the directory to set up your repository, in this case my repository name is "artest" so I will do the following:<br />
<br />
<div class="codeblock">
<div class="title">Code:<br />
</div><div class="body" dir="ltr"><code>mkdir artest<br />
cd artest<br />
git init<br />
touch README<br />
git add README<br />
git commit -m 'first commit'<br />
git remote add origin git@github.com:&lt;USERNAME&gt;/&lt;REPONAME&gt;.git<br />
git push -u origin master</code></div></div>
<br />
Then you're done setting up the repository. You can skip all of the above if you are just going to pull and contribute to an existing repository, and here is how you can do that.<br />
<br />
<span style="font-size: large;"><span style="font-weight: bold;">3) Using Git</span></span><br />
<br />
<span style="font-size: medium;"><span style="font-weight: bold;">Grabbing the files</span></span><br />
If you don't already have the files on your local machine, you can grab them by using the following:<br />
<br />
<div class="codeblock">
<div class="title">Code:<br />
</div><div class="body" dir="ltr"><code>git clone (URL, ie git://github.com/github/linux-2.6.git)</code></div></div>
<br />
<br />
Then you can make your modifications to the file(s), and then to apply your changes to the repository (if you have write access). After you modify a file you will need to add that file to be committed.<br />
<br />
Add a file/directory to be committed:<br />
<br />
<div class="codeblock">
<div class="title">Code:<br />
</div><div class="body" dir="ltr"><code>git add &lt;file/directory&gt;</code></div></div>
<br />
Then once you have added all of your files you can do:<br />
<br />
<div class="codeblock">
<div class="title">Code:<br />
</div><div class="body" dir="ltr"><code>git commit -m "My message letting me know the changes that I have done"</code></div></div>
<br />
Once you've added the file(s) or directories and committed them to your local repo, you then can push your changes to the external server with:<br />
<br />
<div class="codeblock">
<div class="title">Code:<br />
</div><div class="body" dir="ltr"><code>git push</code></div></div>
<br />
Other useful commands<br />
<br />
A command that I personally use frequently is:<br />
<br />
<div class="codeblock">
<div class="title">Code:<br />
</div><div class="body" dir="ltr"><code>git status</code></div></div>
<br />
This will provide you a list of files that have been modified and tell you if they have been added to your commits or not. This quickly lets me know what I am missing or what is actually going to be pushed when I do it.<br />
<br />
<br />
Here is a great website as well to get more commands if you wish to dig in further.<br />
<br />
<blockquote><cite>Quote:</cite><a href="http://gitref.org" target="_blank">http://gitref.org</a></blockquote>
<br />
I'll continue to update this, so keep checking back!]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Creating an SSL vhost in Nginx]]></title>
			<link>http://www.adminreference.com/showthread.php?tid=9</link>
			<pubDate>Sun, 20 Nov 2011 03:30:22 +0000</pubDate>
			<guid isPermaLink="false">http://www.adminreference.com/showthread.php?tid=9</guid>
			<description><![CDATA[If you haven't already read the tutorial I put up about setting up Nginx and configuring virtual hosts, then read <a href="https://www.adminreference.com/showthread.php?tid=1" target="_blank">this thread first.</a><br />
<br />
<span style="font-size: large;">1) Creating a Self Signed Certificate</span><br />
<span style="font-weight: bold;">NOTE:</span> If you have a certificate already, then you can skip this step and go on to step #2<br />
First, make sure you have openssl installed.<br />
<blockquote><cite>Quote:</cite># sudo yum -y install openssl</blockquote>
Now you can use openssl to create your certificate!<br />
<br />
<span style="font-weight: bold;">a)</span> Generate the 1024 bit RSA key, Im going to call this one AR.key, but you can name it whatever you want.<br />
<blockquote><cite>Quote:</cite>[root@svr1 ~]# sudo openssl genrsa -out AR.key 1024<br />
Generating RSA private key, 1024 bit long modulus<br />
...........................................................++++++<br />
....................++++++<br />
e is 65537 (0x10001)</blockquote>
<br />
<span style="font-weight: bold;">b)</span> Using the .key file we made, we can now create a Certificate Signing Request, such as below..<br />
<blockquote><cite>Quote:</cite>[root@svr1 ~]# openssl req -new -key AR.key -out AR.csr<br />
You are about to be asked to enter information that will be incorporated<br />
into your certificate request.<br />
What you are about to enter is what is called a Distinguished Name or a DN.<br />
There are quite a few fields but you can leave some blank<br />
For some fields there will be a default value,<br />
If you enter '.', the field will be left blank.<br />
-----<br />
Country Name (2 letter code) [GB]:US<br />
State or Province Name (full name) [Berkshire]:Arizona<br />
Locality Name (eg, city) [Newbury]:Phoenix<br />
Organization Name (eg, company) [My Company Ltd]:Admin Reference<br />
Organizational Unit Name (eg, section) []:Tech <br />
Common Name (eg, your name or your server's hostname) []:www.adminreference.com<br />
Email Address []:admin@adminreference.com<br />
<br />
Please enter the following 'extra' attributes<br />
to be sent with your certificate request<br />
A challenge password []:password<br />
An optional company name []:</blockquote>
<br />
<span style="font-weight: bold;">c)</span> Finally, generate the certificate, using the .csr and the .key file.<br />
<blockquote><cite>Quote:</cite>[root@svr1 ~]# openssl x509 -req -days 365 -in AR.csr -signkey AR.key -out AR.crt<br />
Signature ok<br />
subject=/C=US/ST=Arizona/L=Phoenix/O=Admin Reference/OU=Tech/CN=www.adminreference.com/emailAddress=admin@adminreference.com<br />
Getting Private key</blockquote>
<br />
DONE! I created the directory /etc/nginx/ssl/ and moved all my certificate related files into that, but you can really put them wherever you want.<br />
<br />
<span style="font-size: large;">2) Implementing the Certificate</span><br />
So basically, all you need to do is copy the non-ssl configuration file, then change "listen 80;" to "listen 443;", then in the same "server" section, add the following:<br />
<blockquote><cite>Quote:</cite>ssl on;<br />
ssl_certificate /etc/nginx/ssl/AR.crt;<br />
ssl_certificate_key /etc/nginx/ssl/AR.key;</blockquote>
<br />
<br />
So the end result should look like this (Not going to go over the details of all the other settings, that would be in the other tutorial:<br />
<div class="codeblock phpcodeblock"><div class="title">PHP Code:<br />
</div><div class="body"><div dir="ltr"><code><span style="color: #0000BB">server&nbsp;</span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">set&nbsp;&#36;domain&nbsp;</span><span style="color: #DD0000">"adminreference.com"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">listen&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;443</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">server_name&nbsp;&nbsp;&#36;domain&nbsp;www</span><span style="color: #007700">.</span><span style="color: #0000BB">&#36;domain</span><span style="color: #007700">;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">ssl&nbsp;on</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">ssl_certificate&nbsp;</span><span style="color: #007700">/</span><span style="color: #0000BB">etc</span><span style="color: #007700">/</span><span style="color: #0000BB">nginx</span><span style="color: #007700">/</span><span style="color: #0000BB">ssl</span><span style="color: #007700">/</span><span style="color: #0000BB">AR</span><span style="color: #007700">.</span><span style="color: #0000BB">crt</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">ssl_certificate_key&nbsp;</span><span style="color: #007700">/</span><span style="color: #0000BB">etc</span><span style="color: #007700">/</span><span style="color: #0000BB">nginx</span><span style="color: #007700">/</span><span style="color: #0000BB">ssl</span><span style="color: #007700">/</span><span style="color: #0000BB">AR</span><span style="color: #007700">.</span><span style="color: #0000BB">key</span><span style="color: #007700">;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(&nbsp;</span><span style="color: #0000BB">&#36;host&nbsp;</span><span style="color: #007700">!~&nbsp;</span><span style="color: #DD0000">"^www.(.*)"&nbsp;</span><span style="color: #007700">)&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">rewrite&nbsp;</span><span style="color: #007700">^/(.*)&#36;&nbsp;</span><span style="color: #0000BB">http</span><span style="color: #007700">:</span><span style="color: #FF8000">//www.&#36;domain/&#36;1&nbsp;permanent;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">access_log&nbsp;</span><span style="color: #DD0000">"/www/</span><span style="color: #0000BB">&#36;domain</span><span style="color: #DD0000">/logs/</span><span style="color: #0000BB">&#36;domain</span><span style="color: #DD0000">-access_log"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">#error_log&nbsp;"/www/&#36;domain/logs/&#36;domain-error_log";<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">location&nbsp;</span><span style="color: #007700">/&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">#&nbsp;Uncomment&nbsp;the&nbsp;following&nbsp;to&nbsp;enable&nbsp;basic&nbsp;authentication<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#auth_basic&nbsp;"Restricted";<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#auth_basic_user_file&nbsp;"/www/&#36;domain/htpasswd";<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">allow&nbsp;all</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">root&nbsp;</span><span style="color: #007700">/</span><span style="color: #0000BB">www</span><span style="color: #007700">/</span><span style="color: #0000BB">&#36;domain</span><span style="color: #007700">/</span><span style="color: #0000BB">htdocs</span><span style="color: #007700">/;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">index&nbsp;index</span><span style="color: #007700">.</span><span style="color: #0000BB">php&nbsp;index</span><span style="color: #007700">.</span><span style="color: #0000BB">html&nbsp;index</span><span style="color: #007700">.</span><span style="color: #0000BB">htm</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">location&nbsp;</span><span style="color: #007700">~&nbsp;&#092;.</span><span style="color: #0000BB">php</span><span style="color: #007700">&#36;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">root&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">/</span><span style="color: #0000BB">www</span><span style="color: #007700">/</span><span style="color: #0000BB">&#36;domain</span><span style="color: #007700">/</span><span style="color: #0000BB">htdocs</span><span style="color: #007700">/;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">fastcgi_pass&nbsp;&nbsp;&nbsp;127.0.0.1</span><span style="color: #007700">:</span><span style="color: #0000BB">9000</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">fastcgi_index&nbsp;&nbsp;index</span><span style="color: #007700">.</span><span style="color: #0000BB">php</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">fastcgi_param&nbsp;&nbsp;SCRIPT_FILENAME&nbsp;&nbsp;&#36;document_root&#36;fastcgi_script_name</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;include&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">fastcgi_params</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">location&nbsp;</span><span style="color: #007700">~&nbsp;/&#092;.</span><span style="color: #0000BB">ht&nbsp;</span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">deny&nbsp;all</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />}&nbsp;<br /></span></code></div></div></div>
]]></description>
			<content:encoded><![CDATA[If you haven't already read the tutorial I put up about setting up Nginx and configuring virtual hosts, then read <a href="https://www.adminreference.com/showthread.php?tid=1" target="_blank">this thread first.</a><br />
<br />
<span style="font-size: large;">1) Creating a Self Signed Certificate</span><br />
<span style="font-weight: bold;">NOTE:</span> If you have a certificate already, then you can skip this step and go on to step #2<br />
First, make sure you have openssl installed.<br />
<blockquote><cite>Quote:</cite># sudo yum -y install openssl</blockquote>
Now you can use openssl to create your certificate!<br />
<br />
<span style="font-weight: bold;">a)</span> Generate the 1024 bit RSA key, Im going to call this one AR.key, but you can name it whatever you want.<br />
<blockquote><cite>Quote:</cite>[root@svr1 ~]# sudo openssl genrsa -out AR.key 1024<br />
Generating RSA private key, 1024 bit long modulus<br />
...........................................................++++++<br />
....................++++++<br />
e is 65537 (0x10001)</blockquote>
<br />
<span style="font-weight: bold;">b)</span> Using the .key file we made, we can now create a Certificate Signing Request, such as below..<br />
<blockquote><cite>Quote:</cite>[root@svr1 ~]# openssl req -new -key AR.key -out AR.csr<br />
You are about to be asked to enter information that will be incorporated<br />
into your certificate request.<br />
What you are about to enter is what is called a Distinguished Name or a DN.<br />
There are quite a few fields but you can leave some blank<br />
For some fields there will be a default value,<br />
If you enter '.', the field will be left blank.<br />
-----<br />
Country Name (2 letter code) [GB]:US<br />
State or Province Name (full name) [Berkshire]:Arizona<br />
Locality Name (eg, city) [Newbury]:Phoenix<br />
Organization Name (eg, company) [My Company Ltd]:Admin Reference<br />
Organizational Unit Name (eg, section) []:Tech <br />
Common Name (eg, your name or your server's hostname) []:www.adminreference.com<br />
Email Address []:admin@adminreference.com<br />
<br />
Please enter the following 'extra' attributes<br />
to be sent with your certificate request<br />
A challenge password []:password<br />
An optional company name []:</blockquote>
<br />
<span style="font-weight: bold;">c)</span> Finally, generate the certificate, using the .csr and the .key file.<br />
<blockquote><cite>Quote:</cite>[root@svr1 ~]# openssl x509 -req -days 365 -in AR.csr -signkey AR.key -out AR.crt<br />
Signature ok<br />
subject=/C=US/ST=Arizona/L=Phoenix/O=Admin Reference/OU=Tech/CN=www.adminreference.com/emailAddress=admin@adminreference.com<br />
Getting Private key</blockquote>
<br />
DONE! I created the directory /etc/nginx/ssl/ and moved all my certificate related files into that, but you can really put them wherever you want.<br />
<br />
<span style="font-size: large;">2) Implementing the Certificate</span><br />
So basically, all you need to do is copy the non-ssl configuration file, then change "listen 80;" to "listen 443;", then in the same "server" section, add the following:<br />
<blockquote><cite>Quote:</cite>ssl on;<br />
ssl_certificate /etc/nginx/ssl/AR.crt;<br />
ssl_certificate_key /etc/nginx/ssl/AR.key;</blockquote>
<br />
<br />
So the end result should look like this (Not going to go over the details of all the other settings, that would be in the other tutorial:<br />
<div class="codeblock phpcodeblock"><div class="title">PHP Code:<br />
</div><div class="body"><div dir="ltr"><code><span style="color: #0000BB">server&nbsp;</span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">set&nbsp;&#36;domain&nbsp;</span><span style="color: #DD0000">"adminreference.com"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">listen&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;443</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">server_name&nbsp;&nbsp;&#36;domain&nbsp;www</span><span style="color: #007700">.</span><span style="color: #0000BB">&#36;domain</span><span style="color: #007700">;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">ssl&nbsp;on</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">ssl_certificate&nbsp;</span><span style="color: #007700">/</span><span style="color: #0000BB">etc</span><span style="color: #007700">/</span><span style="color: #0000BB">nginx</span><span style="color: #007700">/</span><span style="color: #0000BB">ssl</span><span style="color: #007700">/</span><span style="color: #0000BB">AR</span><span style="color: #007700">.</span><span style="color: #0000BB">crt</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">ssl_certificate_key&nbsp;</span><span style="color: #007700">/</span><span style="color: #0000BB">etc</span><span style="color: #007700">/</span><span style="color: #0000BB">nginx</span><span style="color: #007700">/</span><span style="color: #0000BB">ssl</span><span style="color: #007700">/</span><span style="color: #0000BB">AR</span><span style="color: #007700">.</span><span style="color: #0000BB">key</span><span style="color: #007700">;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(&nbsp;</span><span style="color: #0000BB">&#36;host&nbsp;</span><span style="color: #007700">!~&nbsp;</span><span style="color: #DD0000">"^www.(.*)"&nbsp;</span><span style="color: #007700">)&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">rewrite&nbsp;</span><span style="color: #007700">^/(.*)&#36;&nbsp;</span><span style="color: #0000BB">http</span><span style="color: #007700">:</span><span style="color: #FF8000">//www.&#36;domain/&#36;1&nbsp;permanent;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">access_log&nbsp;</span><span style="color: #DD0000">"/www/</span><span style="color: #0000BB">&#36;domain</span><span style="color: #DD0000">/logs/</span><span style="color: #0000BB">&#36;domain</span><span style="color: #DD0000">-access_log"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">#error_log&nbsp;"/www/&#36;domain/logs/&#36;domain-error_log";<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">location&nbsp;</span><span style="color: #007700">/&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">#&nbsp;Uncomment&nbsp;the&nbsp;following&nbsp;to&nbsp;enable&nbsp;basic&nbsp;authentication<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#auth_basic&nbsp;"Restricted";<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#auth_basic_user_file&nbsp;"/www/&#36;domain/htpasswd";<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">allow&nbsp;all</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">root&nbsp;</span><span style="color: #007700">/</span><span style="color: #0000BB">www</span><span style="color: #007700">/</span><span style="color: #0000BB">&#36;domain</span><span style="color: #007700">/</span><span style="color: #0000BB">htdocs</span><span style="color: #007700">/;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">index&nbsp;index</span><span style="color: #007700">.</span><span style="color: #0000BB">php&nbsp;index</span><span style="color: #007700">.</span><span style="color: #0000BB">html&nbsp;index</span><span style="color: #007700">.</span><span style="color: #0000BB">htm</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">location&nbsp;</span><span style="color: #007700">~&nbsp;&#092;.</span><span style="color: #0000BB">php</span><span style="color: #007700">&#36;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">root&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">/</span><span style="color: #0000BB">www</span><span style="color: #007700">/</span><span style="color: #0000BB">&#36;domain</span><span style="color: #007700">/</span><span style="color: #0000BB">htdocs</span><span style="color: #007700">/;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">fastcgi_pass&nbsp;&nbsp;&nbsp;127.0.0.1</span><span style="color: #007700">:</span><span style="color: #0000BB">9000</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">fastcgi_index&nbsp;&nbsp;index</span><span style="color: #007700">.</span><span style="color: #0000BB">php</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">fastcgi_param&nbsp;&nbsp;SCRIPT_FILENAME&nbsp;&nbsp;&#36;document_root&#36;fastcgi_script_name</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;include&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">fastcgi_params</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">location&nbsp;</span><span style="color: #007700">~&nbsp;/&#092;.</span><span style="color: #0000BB">ht&nbsp;</span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">deny&nbsp;all</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />}&nbsp;<br /></span></code></div></div></div>
]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Setting up Nginx on Centos 5.x (With PHP)]]></title>
			<link>http://www.adminreference.com/showthread.php?tid=1</link>
			<pubDate>Sun, 13 Nov 2011 02:56:58 +0000</pubDate>
			<guid isPermaLink="false">http://www.adminreference.com/showthread.php?tid=1</guid>
			<description><![CDATA[While setting up AR, I thought it might be a good idea to learn something new, something to throw on my resume and get some good experience with, so I chose to install <a href="http://nginx.org/" target="_blank">Nginx </a>instead of <a href="http://apache.org" target="_blank">Apache</a>. It was a very quick install, and I can already tell you already that I love it.<br />
<br />
<span style="font-weight: bold;">Why nginx?</span> <a href="http://www.wikivs.com/wiki/Apache_vs_nginx" target="_blank">http://www.wikivs.com/wiki/Apache_vs_nginx</a><br />
<br />
I figured it might be a good idea to write up a quick install tutorial for it, just to give you an idea of how it works and how easy it is to use, just to give you an idea if you would rather use nginx over apache for your next web server.<br />
<br />
<span style="font-weight: bold;">NOTE:</span> In all examples/scripts/configs below, im using adminreference.com for an example domain.<br />
<br />
We are using Centos 5.x on our server, hence we are using YUM for the install, but I'm sure that other than that, it's not a very different setup than any other *nix based systems.<br />
<br />
<span style="font-weight: bold;"><span style="font-size: large;">1) INSTALL</span></span><br />
I installed nginx with yum and just importing the RPM into my repository, if you choose to use this approach, then the command to execute is..<br />
<blockquote><cite>Quote:</cite>rpm -Uvh <a href="http://download.fedora.redhat.com/pub/epel/5Server/%24(uname" target="_blank">http://download.fedora.redhat.com/pub/ep...#36;(uname</a> -i)/epel-release-5-4.noarch.rpm</blockquote>
<span style="font-weight: bold;">NOTE:</span> The version may change, so if that fails, then open that URL up in your web browser and look for the latest epel-release-#-#.noarch.rpm listed.<br />
<br />
If you wish to add the repository to your system, you can do that too. I would look through the nginx website for the instructions: <a href="http://wiki.nginx.org/Install" target="_blank">http://wiki.nginx.org/Install</a><br />
<br />
Now just use yum, and then chkconfig it to make sure it starts up when you reboot the server<br />
<blockquote><cite>Quote:</cite>sudo yum -y install nginx<br />
sudo chkconfig nginx start</blockquote>
<br />
<span style="font-weight: bold;"><span style="font-size: large;">2) CONFIGURE NGINX</span></span><br />
Heres the fun part. One of the reasons I like nginx over apache, is just the config. It's so much cleaner, easier to read and configure. Im not a fan of XML based config files (lighthttpd) or the format that apache uses.<br />
<br />
Heres the default configuration file, just to give you a taste of what the configs look like.<br />
<div class="codeblock phpcodeblock"><div class="title">PHP Code:<br />
</div><div class="body"><div dir="ltr"><code><span style="color: #007700">[</span><span style="color: #0000BB">J</span><span style="color: #007700">@</span><span style="color: #0000BB">svr1&nbsp;</span><span style="color: #007700">~]&#36;&nbsp;</span><span style="color: #0000BB">sudo&nbsp;cat&nbsp;</span><span style="color: #007700">/</span><span style="color: #0000BB">etc</span><span style="color: #007700">/</span><span style="color: #0000BB">nginx</span><span style="color: #007700">/</span><span style="color: #0000BB">nginx</span><span style="color: #007700">.</span><span style="color: #0000BB">conf</span><span style="color: #007700">.default&nbsp;|&nbsp;</span><span style="color: #0000BB">egrep&nbsp;</span><span style="color: #007700">-</span><span style="color: #0000BB">v&nbsp;</span><span style="color: #DD0000">"#|^&#36;"<br /></span><span style="color: #0000BB">worker_processes&nbsp;&nbsp;1</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">events&nbsp;</span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">worker_connections&nbsp;&nbsp;1024</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">http&nbsp;</span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;include&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">mime</span><span style="color: #007700">.</span><span style="color: #0000BB">types</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">default_type&nbsp;&nbsp;application</span><span style="color: #007700">/</span><span style="color: #0000BB">octet</span><span style="color: #007700">-</span><span style="color: #0000BB">stream</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">sendfile&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;on</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">keepalive_timeout&nbsp;&nbsp;65</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">server&nbsp;</span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">listen&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;80</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">server_name&nbsp;&nbsp;localhost</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">location&nbsp;</span><span style="color: #007700">/&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">root&nbsp;&nbsp;&nbsp;html</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">index&nbsp;&nbsp;index</span><span style="color: #007700">.</span><span style="color: #0000BB">html&nbsp;index</span><span style="color: #007700">.</span><span style="color: #0000BB">htm</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">error_page&nbsp;&nbsp;&nbsp;500&nbsp;502&nbsp;503&nbsp;504&nbsp;&nbsp;</span><span style="color: #007700">/</span><span style="color: #0000BB">50x</span><span style="color: #007700">.</span><span style="color: #0000BB">html</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">location&nbsp;</span><span style="color: #007700">=&nbsp;/</span><span style="color: #0000BB">50x</span><span style="color: #007700">.</span><span style="color: #0000BB">html&nbsp;</span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">root&nbsp;&nbsp;&nbsp;html</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}&nbsp;<br /></span></code></div></div></div>
Using that configuration will setup a basic virtualhost that you can view by just going to the IP via your web browser, and see the default nginx configuration file.<br />
<br />
Now heres my configuration file<br />
<div class="codeblock phpcodeblock"><div class="title">PHP Code:<br />
</div><div class="body"><div dir="ltr"><code><span style="color: #007700">[</span><span style="color: #0000BB">J</span><span style="color: #007700">@</span><span style="color: #0000BB">svr1&nbsp;</span><span style="color: #007700">~]&#36;&nbsp;</span><span style="color: #0000BB">sudo&nbsp;cat&nbsp;</span><span style="color: #007700">/</span><span style="color: #0000BB">etc</span><span style="color: #007700">/</span><span style="color: #0000BB">nginx</span><span style="color: #007700">/</span><span style="color: #0000BB">nginx</span><span style="color: #007700">.</span><span style="color: #0000BB">conf&nbsp;</span><span style="color: #007700">|&nbsp;</span><span style="color: #0000BB">egrep&nbsp;</span><span style="color: #007700">-</span><span style="color: #0000BB">v&nbsp;</span><span style="color: #DD0000">"#|^&#36;"<br /></span><span style="color: #0000BB">user&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nginx</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">worker_processes&nbsp;&nbsp;1</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">error_log&nbsp;&nbsp;</span><span style="color: #007700">/var/</span><span style="color: #0000BB">log</span><span style="color: #007700">/</span><span style="color: #0000BB">nginx</span><span style="color: #007700">/</span><span style="color: #0000BB">error</span><span style="color: #007700">.</span><span style="color: #0000BB">log</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">pid&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">/var/</span><span style="color: #0000BB">run</span><span style="color: #007700">/</span><span style="color: #0000BB">nginx</span><span style="color: #007700">.</span><span style="color: #0000BB">pid</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">events&nbsp;</span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">worker_connections&nbsp;&nbsp;1024</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">http&nbsp;</span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;include&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/</span><span style="color: #0000BB">etc</span><span style="color: #007700">/</span><span style="color: #0000BB">nginx</span><span style="color: #007700">/</span><span style="color: #0000BB">mime</span><span style="color: #007700">.</span><span style="color: #0000BB">types</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">default_type&nbsp;&nbsp;application</span><span style="color: #007700">/</span><span style="color: #0000BB">octet</span><span style="color: #007700">-</span><span style="color: #0000BB">stream</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">log_format&nbsp;&nbsp;main&nbsp;&nbsp;</span><span style="color: #DD0000">'&#36;remote_addr&nbsp;-&nbsp;&#36;remote_user&nbsp;[&#36;time_local]&nbsp;"&#36;request"&nbsp;'<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'&#36;status&nbsp;&#36;body_bytes_sent&nbsp;"&#36;http_referer"&nbsp;'<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'"&#36;http_user_agent"&nbsp;"&#36;http_x_forwarded_for"'</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">access_log&nbsp;&nbsp;</span><span style="color: #007700">/var/</span><span style="color: #0000BB">log</span><span style="color: #007700">/</span><span style="color: #0000BB">nginx</span><span style="color: #007700">/</span><span style="color: #0000BB">access</span><span style="color: #007700">.</span><span style="color: #0000BB">log&nbsp;&nbsp;main</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">sendfile&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;on</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">keepalive_timeout&nbsp;&nbsp;65</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">gzip&nbsp;&nbsp;on</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;include&nbsp;/</span><span style="color: #0000BB">etc</span><span style="color: #007700">/</span><span style="color: #0000BB">nginx</span><span style="color: #007700">/</span><span style="color: #0000BB">conf</span><span style="color: #007700">.</span><span style="color: #0000BB">d</span><span style="color: #007700">/</span><span style="color: #0000BB">configs</span><span style="color: #007700">-</span><span style="color: #0000BB">enabled</span><span style="color: #FF8000">/*.conf;<br />&nbsp;&nbsp;&nbsp;&nbsp;include&nbsp;/etc/nginx/conf.d/sites-enabled/*.conf;<br />}&nbsp;<br /></span></code></div></div></div>
<br />
The 3 main differences you will see is the gzip I added for gzip compression, which helps with the load times, and the two includes at the bottom. <br />
<br />
The reason behind these includes are basically just to clean up the directory structure, and make adding/editing/enabling/disabling configurations and virtual hosts very quick and easy. It's a pretty popular method, but I will explain it anyways, if you already know what this is, just skip to the next section of this tutorial.<br />
<br />
Here is the directory structure that I setup for the vhosts and configuration files.<br />
<div class="codeblock phpcodeblock"><div class="title">PHP Code:<br />
</div><div class="body"><div dir="ltr"><code><span style="color: #007700">[</span><span style="color: #0000BB">J</span><span style="color: #007700">@</span><span style="color: #0000BB">svr1&nbsp;</span><span style="color: #007700">~]&#36;&nbsp;</span><span style="color: #0000BB">ls&nbsp;</span><span style="color: #007700">-</span><span style="color: #0000BB">l&nbsp;</span><span style="color: #007700">/</span><span style="color: #0000BB">etc</span><span style="color: #007700">/</span><span style="color: #0000BB">nginx</span><span style="color: #007700">/</span><span style="color: #0000BB">conf</span><span style="color: #007700">.</span><span style="color: #0000BB">d</span><span style="color: #007700">/<br /></span><span style="color: #0000BB">total&nbsp;16<br />drwxr</span><span style="color: #007700">-</span><span style="color: #0000BB">xr</span><span style="color: #007700">-</span><span style="color: #0000BB">x&nbsp;2&nbsp;root&nbsp;root&nbsp;4096&nbsp;Nov&nbsp;11&nbsp;05</span><span style="color: #007700">:</span><span style="color: #0000BB">47&nbsp;configs</span><span style="color: #007700">-</span><span style="color: #0000BB">available<br />drwxr</span><span style="color: #007700">-</span><span style="color: #0000BB">xr</span><span style="color: #007700">-</span><span style="color: #0000BB">x&nbsp;2&nbsp;root&nbsp;root&nbsp;4096&nbsp;Nov&nbsp;11&nbsp;05</span><span style="color: #007700">:</span><span style="color: #0000BB">46&nbsp;configs</span><span style="color: #007700">-</span><span style="color: #0000BB">enabled<br />drwxr</span><span style="color: #007700">-</span><span style="color: #0000BB">xr</span><span style="color: #007700">-</span><span style="color: #0000BB">x&nbsp;2&nbsp;root&nbsp;root&nbsp;4096&nbsp;Nov&nbsp;13&nbsp;04</span><span style="color: #007700">:</span><span style="color: #0000BB">27&nbsp;sites</span><span style="color: #007700">-</span><span style="color: #0000BB">available<br />drwxr</span><span style="color: #007700">-</span><span style="color: #0000BB">xr</span><span style="color: #007700">-</span><span style="color: #0000BB">x&nbsp;2&nbsp;root&nbsp;root&nbsp;4096&nbsp;Nov&nbsp;11&nbsp;07</span><span style="color: #007700">:</span><span style="color: #0000BB">17&nbsp;sites</span><span style="color: #007700">-</span><span style="color: #0000BB">enabled&nbsp;<br /></span></code></div></div></div>
Reason being, is now I can add .conf files to configs-available and sites-available, then simply symlink them into the configs-enabled and sites-enabled directories.<br />
<div class="codeblock phpcodeblock"><div class="title">PHP Code:<br />
</div><div class="body"><div dir="ltr"><code><span style="color: #007700">[</span><span style="color: #0000BB">J</span><span style="color: #007700">@</span><span style="color: #0000BB">svr1&nbsp;</span><span style="color: #007700">~]&#36;&nbsp;</span><span style="color: #0000BB">ls&nbsp;</span><span style="color: #007700">-</span><span style="color: #0000BB">l&nbsp;</span><span style="color: #007700">/</span><span style="color: #0000BB">etc</span><span style="color: #007700">/</span><span style="color: #0000BB">nginx</span><span style="color: #007700">/</span><span style="color: #0000BB">conf</span><span style="color: #007700">.</span><span style="color: #0000BB">d</span><span style="color: #007700">/</span><span style="color: #0000BB">sites</span><span style="color: #007700">-</span><span style="color: #0000BB">enabled<br />total&nbsp;0<br />lrwxrwxrwx&nbsp;1&nbsp;root&nbsp;root&nbsp;57&nbsp;Nov&nbsp;11&nbsp;05</span><span style="color: #007700">:</span><span style="color: #0000BB">50&nbsp;adminreference</span><span style="color: #007700">.</span><span style="color: #0000BB">com</span><span style="color: #007700">.</span><span style="color: #0000BB">conf&nbsp;</span><span style="color: #007700">-&gt;&nbsp;/</span><span style="color: #0000BB">etc</span><span style="color: #007700">/</span><span style="color: #0000BB">nginx</span><span style="color: #007700">/</span><span style="color: #0000BB">conf</span><span style="color: #007700">.</span><span style="color: #0000BB">d</span><span style="color: #007700">/</span><span style="color: #0000BB">sites</span><span style="color: #007700">-</span><span style="color: #0000BB">available</span><span style="color: #007700">/</span><span style="color: #0000BB">adminreference</span><span style="color: #007700">.</span><span style="color: #0000BB">com</span><span style="color: #007700">.</span><span style="color: #0000BB">conf<br />lrwxrwxrwx&nbsp;1&nbsp;root&nbsp;root&nbsp;42&nbsp;Nov&nbsp;11&nbsp;05</span><span style="color: #007700">:</span><span style="color: #0000BB">50&nbsp;ssl</span><span style="color: #007700">.</span><span style="color: #0000BB">conf&nbsp;</span><span style="color: #007700">-&gt;&nbsp;/</span><span style="color: #0000BB">etc</span><span style="color: #007700">/</span><span style="color: #0000BB">nginx</span><span style="color: #007700">/</span><span style="color: #0000BB">conf</span><span style="color: #007700">.</span><span style="color: #0000BB">d</span><span style="color: #007700">/</span><span style="color: #0000BB">sites</span><span style="color: #007700">-</span><span style="color: #0000BB">available</span><span style="color: #007700">/</span><span style="color: #0000BB">ssl</span><span style="color: #007700">.</span><span style="color: #0000BB">conf<br />lrwxrwxrwx&nbsp;1&nbsp;root&nbsp;root&nbsp;46&nbsp;Nov&nbsp;11&nbsp;05</span><span style="color: #007700">:</span><span style="color: #0000BB">50&nbsp;virtual</span><span style="color: #007700">.</span><span style="color: #0000BB">conf&nbsp;</span><span style="color: #007700">-&gt;&nbsp;/</span><span style="color: #0000BB">etc</span><span style="color: #007700">/</span><span style="color: #0000BB">nginx</span><span style="color: #007700">/</span><span style="color: #0000BB">conf</span><span style="color: #007700">.</span><span style="color: #0000BB">d</span><span style="color: #007700">/</span><span style="color: #0000BB">sites</span><span style="color: #007700">-</span><span style="color: #0000BB">available</span><span style="color: #007700">/</span><span style="color: #0000BB">virtual</span><span style="color: #007700">.</span><span style="color: #0000BB">conf<br />lrwxrwxrwx&nbsp;1&nbsp;root&nbsp;root&nbsp;54&nbsp;Nov&nbsp;11&nbsp;05</span><span style="color: #007700">:</span><span style="color: #0000BB">50&nbsp;virtualhost</span><span style="color: #007700">.</span><span style="color: #0000BB">template&nbsp;</span><span style="color: #007700">-&gt;&nbsp;/</span><span style="color: #0000BB">etc</span><span style="color: #007700">/</span><span style="color: #0000BB">nginx</span><span style="color: #007700">/</span><span style="color: #0000BB">conf</span><span style="color: #007700">.</span><span style="color: #0000BB">d</span><span style="color: #007700">/</span><span style="color: #0000BB">sites</span><span style="color: #007700">-</span><span style="color: #0000BB">available</span><span style="color: #007700">/</span><span style="color: #0000BB">virtualhost</span><span style="color: #007700">.</span><span style="color: #0000BB">template&nbsp;<br /></span></code></div></div></div>
To symlink a configuration file, just..<br />
<div class="codeblock phpcodeblock"><div class="title">PHP Code:<br />
</div><div class="body"><div dir="ltr"><code><span style="color: #0000BB">sudo&nbsp;ln&nbsp;</span><span style="color: #007700">-</span><span style="color: #0000BB">s&nbsp;</span><span style="color: #007700">-</span><span style="color: #0000BB">v&nbsp;</span><span style="color: #007700">/</span><span style="color: #0000BB">etc</span><span style="color: #007700">/</span><span style="color: #0000BB">nginx</span><span style="color: #007700">/</span><span style="color: #0000BB">conf</span><span style="color: #007700">.</span><span style="color: #0000BB">d</span><span style="color: #007700">/</span><span style="color: #0000BB">sites</span><span style="color: #007700">-</span><span style="color: #0000BB">available</span><span style="color: #007700">/</span><span style="color: #0000BB">configuration</span><span style="color: #007700">.</span><span style="color: #0000BB">conf&nbsp;</span><span style="color: #007700">/</span><span style="color: #0000BB">etc</span><span style="color: #007700">/</span><span style="color: #0000BB">nginx</span><span style="color: #007700">/</span><span style="color: #0000BB">conf</span><span style="color: #007700">.</span><span style="color: #0000BB">d</span><span style="color: #007700">/</span><span style="color: #0000BB">sites</span><span style="color: #007700">-</span><span style="color: #0000BB">enabled</span><span style="color: #007700">/</span><span style="color: #0000BB">configuration</span><span style="color: #007700">.</span><span style="color: #0000BB">conf&nbsp;</span><span style="color: #007700">||&nbsp;exit&nbsp;</span><span style="color: #0000BB">1&nbsp;<br /></span></code></div></div></div>
Pretty simple right? This is common practice for a lot of web server configuration file structures.<br />
<br />
<span style="font-weight: bold;"><span style="font-size: large;">3) CONFIGURE PHP</span></span><br />
Using YUM..<br />
<blockquote><cite>Quote:</cite>sudo yum install php-pear-Net-Socket php-pear php-common php-gd php-devel php php-mbstring php-pear-Mail php-cli php-imap php-snmp php-pdo php-xml php-pear-Auth-SASL php-ldap php-pear-Net-SMTP php-mysql</blockquote>
Now make sure it got installed properly..<br />
<blockquote><cite>Quote:</cite>[J@svr1 ~]&#36; php-cgi -v<br />
PHP 5.1.6 (cgi-fcgi) (built: Nov 29 2010 16:43:56)<br />
Copyright &copy; 1997-2006 The PHP Group<br />
Zend Engine v2.1.0, Copyright &copy; 1998-2006 Zend Technologies</blockquote>
<br />
Now you need to add the php_cgi init.d script to get it started properly. I found a decent one on the web, but it had a few flaws, so I took the liberty of modifying it a bit and uploading it to the server. Download/install it using:<br />
<blockquote><cite>Quote:</cite>wget <a href="http://www.adminreference.com/scripts/nginx/php_cgi.txt" target="_blank">http://www.adminreference.com/scripts/nginx/php_cgi.txt</a> -O /etc/init.d/php_cgi<br />
sudo chmod +x /etc/init.d/php_cgi<br />
sudo chkconfig php_cgi on<br />
sudo /etc/init.d/php_cgi start</blockquote>
<br />
If the above fails due to not having spawn-fcgi installed, you can run the following commands to install that as well.<br />
<blockquote><cite>Quote:</cite>wget <a href="http://www.lighttpd.net/download/lighttpd-1.4.18.tar.bz2" target="_blank">http://www.lighttpd.net/download/lighttp...18.tar.bz2</a><br />
tar -xvjf lighttpd-1.4.18.tar.bz2<br />
cd lighttpd-1.4.18/<br />
./configure<br />
make<br />
sudo cp src/spawn-fcgi /usr/bin/spawn-fcgi<br />
sudo +x /usr/bin/spawn-fcgi</blockquote>
<br />
After thats done, you can delete the downloaded content:<br />
<blockquote><cite>Quote:</cite>cd ..<br />
rm -rf lighttpd-1.4.18/<br />
rm lighttpd-1.4.18.tar.bz2</blockquote>
<br />
<span style="font-weight: bold;"><span style="font-size: large;">4) ADD A VHOST</span></span><br />
Heres the configuration file for AR at the time this tutorial was written.<br />
<div class="codeblock phpcodeblock"><div class="title">PHP Code:<br />
</div><div class="body"><div dir="ltr"><code><span style="color: #007700">[</span><span style="color: #0000BB">J</span><span style="color: #007700">@</span><span style="color: #0000BB">svr1&nbsp;</span><span style="color: #007700">~]&#36;&nbsp;</span><span style="color: #0000BB">sudo&nbsp;cat&nbsp;</span><span style="color: #007700">/</span><span style="color: #0000BB">etc</span><span style="color: #007700">/</span><span style="color: #0000BB">nginx</span><span style="color: #007700">/</span><span style="color: #0000BB">conf</span><span style="color: #007700">.</span><span style="color: #0000BB">d</span><span style="color: #007700">/</span><span style="color: #0000BB">sites</span><span style="color: #007700">-</span><span style="color: #0000BB">available</span><span style="color: #007700">/</span><span style="color: #0000BB">adminreference</span><span style="color: #007700">.</span><span style="color: #0000BB">com</span><span style="color: #007700">.</span><span style="color: #0000BB">conf<br /></span><span style="color: #FF8000">#&nbsp;HOST:&nbsp;adminreference.com<br />#&nbsp;DATE:&nbsp;Thu&nbsp;Nov&nbsp;10&nbsp;03:39:15&nbsp;MST&nbsp;2011<br />#<br /><br /></span><span style="color: #0000BB">server&nbsp;</span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">set&nbsp;&#36;domain&nbsp;</span><span style="color: #DD0000">"adminreference.com"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">listen&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;80</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">server_name&nbsp;&nbsp;&#36;domain&nbsp;www</span><span style="color: #007700">.</span><span style="color: #0000BB">&#36;domain</span><span style="color: #007700">;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(&nbsp;</span><span style="color: #0000BB">&#36;host&nbsp;</span><span style="color: #007700">!~&nbsp;</span><span style="color: #DD0000">"^www.(.*)"&nbsp;</span><span style="color: #007700">)&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">rewrite&nbsp;</span><span style="color: #007700">^/(.*)&#36;&nbsp;</span><span style="color: #0000BB">http</span><span style="color: #007700">:</span><span style="color: #FF8000">//www.&#36;domain/&#36;1&nbsp;permanent;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">access_log&nbsp;</span><span style="color: #DD0000">"/www/</span><span style="color: #0000BB">&#36;domain</span><span style="color: #DD0000">/logs/</span><span style="color: #0000BB">&#36;domain</span><span style="color: #DD0000">-access_log"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">#error_log&nbsp;"/www/&#36;domain/logs/&#36;domain-error_log";<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">location&nbsp;</span><span style="color: #007700">/&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">#allow&nbsp;all;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">auth_basic&nbsp;</span><span style="color: #DD0000">"Restricted"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">auth_basic_user_file&nbsp;</span><span style="color: #DD0000">"/www/</span><span style="color: #0000BB">&#36;domain</span><span style="color: #DD0000">/htpasswd"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">root&nbsp;</span><span style="color: #007700">/</span><span style="color: #0000BB">www</span><span style="color: #007700">/</span><span style="color: #0000BB">&#36;domain</span><span style="color: #007700">/</span><span style="color: #0000BB">htdocs</span><span style="color: #007700">/;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">index&nbsp;index</span><span style="color: #007700">.</span><span style="color: #0000BB">php&nbsp;index</span><span style="color: #007700">.</span><span style="color: #0000BB">html&nbsp;index</span><span style="color: #007700">.</span><span style="color: #0000BB">htm</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">location&nbsp;</span><span style="color: #007700">~&nbsp;&#092;.</span><span style="color: #0000BB">php</span><span style="color: #007700">&#36;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">root&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">/</span><span style="color: #0000BB">www</span><span style="color: #007700">/</span><span style="color: #0000BB">&#36;domain</span><span style="color: #007700">/</span><span style="color: #0000BB">htdocs</span><span style="color: #007700">/;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">fastcgi_pass&nbsp;&nbsp;&nbsp;127.0.0.1</span><span style="color: #007700">:</span><span style="color: #0000BB">9000</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">fastcgi_index&nbsp;&nbsp;index</span><span style="color: #007700">.</span><span style="color: #0000BB">php</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">fastcgi_param&nbsp;&nbsp;SCRIPT_FILENAME&nbsp;&nbsp;&#36;document_root&#36;fastcgi_script_name</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;include&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">fastcgi_params</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">location&nbsp;</span><span style="color: #007700">~&nbsp;/&#092;.</span><span style="color: #0000BB">ht&nbsp;</span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">deny&nbsp;all</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />}&nbsp;<br /></span></code></div></div></div>
I like the fact that you can use if statements and set variables in the configuration files makes life so much easier...<br />
<br />
With the above configuration, the new vhost is setup like so..<ul>
<li>Error Log: /www/adminreference.com/logs/adminreference.om-error_log (which is a symlink to /var/log/nginx/adminreference.om-error_log)</li>
<li>Access Log: Same as the error log, only access_log</li>
<li>Restricted access to all .ht* files (.htaccess, .htpasswd, etc)</li>
<li>Setup a 301 redirect from non-www to www</li>
<li>Enabled PHP for the vhost</li>
<li>Set the default pages to index.php index.html index.htm (in that order)</li>
<li>etc, I think you can understand it from the configuration file itself<br />
</li></ul>
<br />
<span style="font-weight: bold;"><span style="font-size: large;">5) DONE!</span></span><br />
Thats pretty much it, you can now test the configurations and reload nginx by running:<br />
<blockquote><cite>Quote:</cite>sudo /etc/init.d/nginx reload</blockquote>
<br />
Now to make life easier, I created a simple bash script that will automatically add a new vhost, you can download it by running:<br />
<blockquote><cite>Quote:</cite>wget <a href="http://www.adminreference.com/scripts/nginx/create_nginx_site.sh.txt" target="_blank">http://www.adminreference.com/scripts/ng...ite.sh.txt</a> -O create_nginx_site.sh</blockquote>
You will also need the template file..<br />
<blockquote><cite>Quote:</cite>wget <a href="http://www.adminreference.com/scripts/nginx/virtualhost.template.txt" target="_blank">http://www.adminreference.com/scripts/ng...mplate.txt</a> -O virtualhost.template</blockquote>
<br />
Heres the sample output:<br />
<blockquote><cite>Quote:</cite>sudo /bin/bash create_nginx_site.sh -h google.com<br />
`/etc/nginx/conf.d/sites-available/virtualhost.template' -&gt; `/etc/nginx/conf.d/sites-available/google.com.conf'<br />
mkdir: created directory `/www/google.com'<br />
mkdir: created directory `/www/google.com/htdocs'<br />
create symbolic link `/www/google.com/logs' to `/var/log/nginx'<br />
changed ownership of `/www/google.com/htdocs/index.php' to nginx:nginx<br />
changed ownership of `/www/google.com/htdocs' to nginx:nginx<br />
changed ownership of `/www/google.com/logs' to nginx:nginx<br />
changed ownership of `/www/google.com' to nginx:nginx<br />
mode of `/www/google.com' retained as 0755 (rwxr-xr-x)<br />
mode of `/www/google.com/htdocs' retained as 0755 (rwxr-xr-x)<br />
mode of `/www/google.com/htdocs/index.php' changed to 0755 (rwxr-xr-x)<br />
neither symbolic link `/www/google.com/logs' nor referent has been changed<br />
changed ownership of `/www/google.com/logs/google.com-access_log' to nginx:nginx<br />
changed ownership of `/www/google.com/logs/google.com-error_log' to nginx:nginx<br />
the configuration file /etc/nginx/nginx.conf syntax is ok<br />
configuration file /etc/nginx/nginx.conf test is successful<br />
Reloading nginx:                                           [  OK  ]<br />
Nginx reloaded! Everyting looks good</blockquote>
The script will..<ul>
<li>Copy/rename the template to the sites-available directory</li>
<li>Create the www directory and htdocs directory</li>
<li>Symlink the logs to /var/log/nginx</li>
<li>Change ownerships to nginx and perms to rwxr-xr-x</li>
<li>Create the access and error log</li>
<li>Create a sample php page for php test (/php.php)</li>
<li>Check the configuration and then reload nginx<br />
</li></ul>
<br />
Thats it! If you run into any bugs, please let me know so I can update the tutorial]]></description>
			<content:encoded><![CDATA[While setting up AR, I thought it might be a good idea to learn something new, something to throw on my resume and get some good experience with, so I chose to install <a href="http://nginx.org/" target="_blank">Nginx </a>instead of <a href="http://apache.org" target="_blank">Apache</a>. It was a very quick install, and I can already tell you already that I love it.<br />
<br />
<span style="font-weight: bold;">Why nginx?</span> <a href="http://www.wikivs.com/wiki/Apache_vs_nginx" target="_blank">http://www.wikivs.com/wiki/Apache_vs_nginx</a><br />
<br />
I figured it might be a good idea to write up a quick install tutorial for it, just to give you an idea of how it works and how easy it is to use, just to give you an idea if you would rather use nginx over apache for your next web server.<br />
<br />
<span style="font-weight: bold;">NOTE:</span> In all examples/scripts/configs below, im using adminreference.com for an example domain.<br />
<br />
We are using Centos 5.x on our server, hence we are using YUM for the install, but I'm sure that other than that, it's not a very different setup than any other *nix based systems.<br />
<br />
<span style="font-weight: bold;"><span style="font-size: large;">1) INSTALL</span></span><br />
I installed nginx with yum and just importing the RPM into my repository, if you choose to use this approach, then the command to execute is..<br />
<blockquote><cite>Quote:</cite>rpm -Uvh <a href="http://download.fedora.redhat.com/pub/epel/5Server/%24(uname" target="_blank">http://download.fedora.redhat.com/pub/ep...#36;(uname</a> -i)/epel-release-5-4.noarch.rpm</blockquote>
<span style="font-weight: bold;">NOTE:</span> The version may change, so if that fails, then open that URL up in your web browser and look for the latest epel-release-#-#.noarch.rpm listed.<br />
<br />
If you wish to add the repository to your system, you can do that too. I would look through the nginx website for the instructions: <a href="http://wiki.nginx.org/Install" target="_blank">http://wiki.nginx.org/Install</a><br />
<br />
Now just use yum, and then chkconfig it to make sure it starts up when you reboot the server<br />
<blockquote><cite>Quote:</cite>sudo yum -y install nginx<br />
sudo chkconfig nginx start</blockquote>
<br />
<span style="font-weight: bold;"><span style="font-size: large;">2) CONFIGURE NGINX</span></span><br />
Heres the fun part. One of the reasons I like nginx over apache, is just the config. It's so much cleaner, easier to read and configure. Im not a fan of XML based config files (lighthttpd) or the format that apache uses.<br />
<br />
Heres the default configuration file, just to give you a taste of what the configs look like.<br />
<div class="codeblock phpcodeblock"><div class="title">PHP Code:<br />
</div><div class="body"><div dir="ltr"><code><span style="color: #007700">[</span><span style="color: #0000BB">J</span><span style="color: #007700">@</span><span style="color: #0000BB">svr1&nbsp;</span><span style="color: #007700">~]&#36;&nbsp;</span><span style="color: #0000BB">sudo&nbsp;cat&nbsp;</span><span style="color: #007700">/</span><span style="color: #0000BB">etc</span><span style="color: #007700">/</span><span style="color: #0000BB">nginx</span><span style="color: #007700">/</span><span style="color: #0000BB">nginx</span><span style="color: #007700">.</span><span style="color: #0000BB">conf</span><span style="color: #007700">.default&nbsp;|&nbsp;</span><span style="color: #0000BB">egrep&nbsp;</span><span style="color: #007700">-</span><span style="color: #0000BB">v&nbsp;</span><span style="color: #DD0000">"#|^&#36;"<br /></span><span style="color: #0000BB">worker_processes&nbsp;&nbsp;1</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">events&nbsp;</span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">worker_connections&nbsp;&nbsp;1024</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">http&nbsp;</span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;include&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">mime</span><span style="color: #007700">.</span><span style="color: #0000BB">types</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">default_type&nbsp;&nbsp;application</span><span style="color: #007700">/</span><span style="color: #0000BB">octet</span><span style="color: #007700">-</span><span style="color: #0000BB">stream</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">sendfile&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;on</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">keepalive_timeout&nbsp;&nbsp;65</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">server&nbsp;</span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">listen&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;80</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">server_name&nbsp;&nbsp;localhost</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">location&nbsp;</span><span style="color: #007700">/&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">root&nbsp;&nbsp;&nbsp;html</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">index&nbsp;&nbsp;index</span><span style="color: #007700">.</span><span style="color: #0000BB">html&nbsp;index</span><span style="color: #007700">.</span><span style="color: #0000BB">htm</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">error_page&nbsp;&nbsp;&nbsp;500&nbsp;502&nbsp;503&nbsp;504&nbsp;&nbsp;</span><span style="color: #007700">/</span><span style="color: #0000BB">50x</span><span style="color: #007700">.</span><span style="color: #0000BB">html</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">location&nbsp;</span><span style="color: #007700">=&nbsp;/</span><span style="color: #0000BB">50x</span><span style="color: #007700">.</span><span style="color: #0000BB">html&nbsp;</span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">root&nbsp;&nbsp;&nbsp;html</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}&nbsp;<br /></span></code></div></div></div>
Using that configuration will setup a basic virtualhost that you can view by just going to the IP via your web browser, and see the default nginx configuration file.<br />
<br />
Now heres my configuration file<br />
<div class="codeblock phpcodeblock"><div class="title">PHP Code:<br />
</div><div class="body"><div dir="ltr"><code><span style="color: #007700">[</span><span style="color: #0000BB">J</span><span style="color: #007700">@</span><span style="color: #0000BB">svr1&nbsp;</span><span style="color: #007700">~]&#36;&nbsp;</span><span style="color: #0000BB">sudo&nbsp;cat&nbsp;</span><span style="color: #007700">/</span><span style="color: #0000BB">etc</span><span style="color: #007700">/</span><span style="color: #0000BB">nginx</span><span style="color: #007700">/</span><span style="color: #0000BB">nginx</span><span style="color: #007700">.</span><span style="color: #0000BB">conf&nbsp;</span><span style="color: #007700">|&nbsp;</span><span style="color: #0000BB">egrep&nbsp;</span><span style="color: #007700">-</span><span style="color: #0000BB">v&nbsp;</span><span style="color: #DD0000">"#|^&#36;"<br /></span><span style="color: #0000BB">user&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nginx</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">worker_processes&nbsp;&nbsp;1</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">error_log&nbsp;&nbsp;</span><span style="color: #007700">/var/</span><span style="color: #0000BB">log</span><span style="color: #007700">/</span><span style="color: #0000BB">nginx</span><span style="color: #007700">/</span><span style="color: #0000BB">error</span><span style="color: #007700">.</span><span style="color: #0000BB">log</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">pid&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">/var/</span><span style="color: #0000BB">run</span><span style="color: #007700">/</span><span style="color: #0000BB">nginx</span><span style="color: #007700">.</span><span style="color: #0000BB">pid</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">events&nbsp;</span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">worker_connections&nbsp;&nbsp;1024</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">http&nbsp;</span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;include&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/</span><span style="color: #0000BB">etc</span><span style="color: #007700">/</span><span style="color: #0000BB">nginx</span><span style="color: #007700">/</span><span style="color: #0000BB">mime</span><span style="color: #007700">.</span><span style="color: #0000BB">types</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">default_type&nbsp;&nbsp;application</span><span style="color: #007700">/</span><span style="color: #0000BB">octet</span><span style="color: #007700">-</span><span style="color: #0000BB">stream</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">log_format&nbsp;&nbsp;main&nbsp;&nbsp;</span><span style="color: #DD0000">'&#36;remote_addr&nbsp;-&nbsp;&#36;remote_user&nbsp;[&#36;time_local]&nbsp;"&#36;request"&nbsp;'<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'&#36;status&nbsp;&#36;body_bytes_sent&nbsp;"&#36;http_referer"&nbsp;'<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'"&#36;http_user_agent"&nbsp;"&#36;http_x_forwarded_for"'</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">access_log&nbsp;&nbsp;</span><span style="color: #007700">/var/</span><span style="color: #0000BB">log</span><span style="color: #007700">/</span><span style="color: #0000BB">nginx</span><span style="color: #007700">/</span><span style="color: #0000BB">access</span><span style="color: #007700">.</span><span style="color: #0000BB">log&nbsp;&nbsp;main</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">sendfile&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;on</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">keepalive_timeout&nbsp;&nbsp;65</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">gzip&nbsp;&nbsp;on</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;include&nbsp;/</span><span style="color: #0000BB">etc</span><span style="color: #007700">/</span><span style="color: #0000BB">nginx</span><span style="color: #007700">/</span><span style="color: #0000BB">conf</span><span style="color: #007700">.</span><span style="color: #0000BB">d</span><span style="color: #007700">/</span><span style="color: #0000BB">configs</span><span style="color: #007700">-</span><span style="color: #0000BB">enabled</span><span style="color: #FF8000">/*.conf;<br />&nbsp;&nbsp;&nbsp;&nbsp;include&nbsp;/etc/nginx/conf.d/sites-enabled/*.conf;<br />}&nbsp;<br /></span></code></div></div></div>
<br />
The 3 main differences you will see is the gzip I added for gzip compression, which helps with the load times, and the two includes at the bottom. <br />
<br />
The reason behind these includes are basically just to clean up the directory structure, and make adding/editing/enabling/disabling configurations and virtual hosts very quick and easy. It's a pretty popular method, but I will explain it anyways, if you already know what this is, just skip to the next section of this tutorial.<br />
<br />
Here is the directory structure that I setup for the vhosts and configuration files.<br />
<div class="codeblock phpcodeblock"><div class="title">PHP Code:<br />
</div><div class="body"><div dir="ltr"><code><span style="color: #007700">[</span><span style="color: #0000BB">J</span><span style="color: #007700">@</span><span style="color: #0000BB">svr1&nbsp;</span><span style="color: #007700">~]&#36;&nbsp;</span><span style="color: #0000BB">ls&nbsp;</span><span style="color: #007700">-</span><span style="color: #0000BB">l&nbsp;</span><span style="color: #007700">/</span><span style="color: #0000BB">etc</span><span style="color: #007700">/</span><span style="color: #0000BB">nginx</span><span style="color: #007700">/</span><span style="color: #0000BB">conf</span><span style="color: #007700">.</span><span style="color: #0000BB">d</span><span style="color: #007700">/<br /></span><span style="color: #0000BB">total&nbsp;16<br />drwxr</span><span style="color: #007700">-</span><span style="color: #0000BB">xr</span><span style="color: #007700">-</span><span style="color: #0000BB">x&nbsp;2&nbsp;root&nbsp;root&nbsp;4096&nbsp;Nov&nbsp;11&nbsp;05</span><span style="color: #007700">:</span><span style="color: #0000BB">47&nbsp;configs</span><span style="color: #007700">-</span><span style="color: #0000BB">available<br />drwxr</span><span style="color: #007700">-</span><span style="color: #0000BB">xr</span><span style="color: #007700">-</span><span style="color: #0000BB">x&nbsp;2&nbsp;root&nbsp;root&nbsp;4096&nbsp;Nov&nbsp;11&nbsp;05</span><span style="color: #007700">:</span><span style="color: #0000BB">46&nbsp;configs</span><span style="color: #007700">-</span><span style="color: #0000BB">enabled<br />drwxr</span><span style="color: #007700">-</span><span style="color: #0000BB">xr</span><span style="color: #007700">-</span><span style="color: #0000BB">x&nbsp;2&nbsp;root&nbsp;root&nbsp;4096&nbsp;Nov&nbsp;13&nbsp;04</span><span style="color: #007700">:</span><span style="color: #0000BB">27&nbsp;sites</span><span style="color: #007700">-</span><span style="color: #0000BB">available<br />drwxr</span><span style="color: #007700">-</span><span style="color: #0000BB">xr</span><span style="color: #007700">-</span><span style="color: #0000BB">x&nbsp;2&nbsp;root&nbsp;root&nbsp;4096&nbsp;Nov&nbsp;11&nbsp;07</span><span style="color: #007700">:</span><span style="color: #0000BB">17&nbsp;sites</span><span style="color: #007700">-</span><span style="color: #0000BB">enabled&nbsp;<br /></span></code></div></div></div>
Reason being, is now I can add .conf files to configs-available and sites-available, then simply symlink them into the configs-enabled and sites-enabled directories.<br />
<div class="codeblock phpcodeblock"><div class="title">PHP Code:<br />
</div><div class="body"><div dir="ltr"><code><span style="color: #007700">[</span><span style="color: #0000BB">J</span><span style="color: #007700">@</span><span style="color: #0000BB">svr1&nbsp;</span><span style="color: #007700">~]&#36;&nbsp;</span><span style="color: #0000BB">ls&nbsp;</span><span style="color: #007700">-</span><span style="color: #0000BB">l&nbsp;</span><span style="color: #007700">/</span><span style="color: #0000BB">etc</span><span style="color: #007700">/</span><span style="color: #0000BB">nginx</span><span style="color: #007700">/</span><span style="color: #0000BB">conf</span><span style="color: #007700">.</span><span style="color: #0000BB">d</span><span style="color: #007700">/</span><span style="color: #0000BB">sites</span><span style="color: #007700">-</span><span style="color: #0000BB">enabled<br />total&nbsp;0<br />lrwxrwxrwx&nbsp;1&nbsp;root&nbsp;root&nbsp;57&nbsp;Nov&nbsp;11&nbsp;05</span><span style="color: #007700">:</span><span style="color: #0000BB">50&nbsp;adminreference</span><span style="color: #007700">.</span><span style="color: #0000BB">com</span><span style="color: #007700">.</span><span style="color: #0000BB">conf&nbsp;</span><span style="color: #007700">-&gt;&nbsp;/</span><span style="color: #0000BB">etc</span><span style="color: #007700">/</span><span style="color: #0000BB">nginx</span><span style="color: #007700">/</span><span style="color: #0000BB">conf</span><span style="color: #007700">.</span><span style="color: #0000BB">d</span><span style="color: #007700">/</span><span style="color: #0000BB">sites</span><span style="color: #007700">-</span><span style="color: #0000BB">available</span><span style="color: #007700">/</span><span style="color: #0000BB">adminreference</span><span style="color: #007700">.</span><span style="color: #0000BB">com</span><span style="color: #007700">.</span><span style="color: #0000BB">conf<br />lrwxrwxrwx&nbsp;1&nbsp;root&nbsp;root&nbsp;42&nbsp;Nov&nbsp;11&nbsp;05</span><span style="color: #007700">:</span><span style="color: #0000BB">50&nbsp;ssl</span><span style="color: #007700">.</span><span style="color: #0000BB">conf&nbsp;</span><span style="color: #007700">-&gt;&nbsp;/</span><span style="color: #0000BB">etc</span><span style="color: #007700">/</span><span style="color: #0000BB">nginx</span><span style="color: #007700">/</span><span style="color: #0000BB">conf</span><span style="color: #007700">.</span><span style="color: #0000BB">d</span><span style="color: #007700">/</span><span style="color: #0000BB">sites</span><span style="color: #007700">-</span><span style="color: #0000BB">available</span><span style="color: #007700">/</span><span style="color: #0000BB">ssl</span><span style="color: #007700">.</span><span style="color: #0000BB">conf<br />lrwxrwxrwx&nbsp;1&nbsp;root&nbsp;root&nbsp;46&nbsp;Nov&nbsp;11&nbsp;05</span><span style="color: #007700">:</span><span style="color: #0000BB">50&nbsp;virtual</span><span style="color: #007700">.</span><span style="color: #0000BB">conf&nbsp;</span><span style="color: #007700">-&gt;&nbsp;/</span><span style="color: #0000BB">etc</span><span style="color: #007700">/</span><span style="color: #0000BB">nginx</span><span style="color: #007700">/</span><span style="color: #0000BB">conf</span><span style="color: #007700">.</span><span style="color: #0000BB">d</span><span style="color: #007700">/</span><span style="color: #0000BB">sites</span><span style="color: #007700">-</span><span style="color: #0000BB">available</span><span style="color: #007700">/</span><span style="color: #0000BB">virtual</span><span style="color: #007700">.</span><span style="color: #0000BB">conf<br />lrwxrwxrwx&nbsp;1&nbsp;root&nbsp;root&nbsp;54&nbsp;Nov&nbsp;11&nbsp;05</span><span style="color: #007700">:</span><span style="color: #0000BB">50&nbsp;virtualhost</span><span style="color: #007700">.</span><span style="color: #0000BB">template&nbsp;</span><span style="color: #007700">-&gt;&nbsp;/</span><span style="color: #0000BB">etc</span><span style="color: #007700">/</span><span style="color: #0000BB">nginx</span><span style="color: #007700">/</span><span style="color: #0000BB">conf</span><span style="color: #007700">.</span><span style="color: #0000BB">d</span><span style="color: #007700">/</span><span style="color: #0000BB">sites</span><span style="color: #007700">-</span><span style="color: #0000BB">available</span><span style="color: #007700">/</span><span style="color: #0000BB">virtualhost</span><span style="color: #007700">.</span><span style="color: #0000BB">template&nbsp;<br /></span></code></div></div></div>
To symlink a configuration file, just..<br />
<div class="codeblock phpcodeblock"><div class="title">PHP Code:<br />
</div><div class="body"><div dir="ltr"><code><span style="color: #0000BB">sudo&nbsp;ln&nbsp;</span><span style="color: #007700">-</span><span style="color: #0000BB">s&nbsp;</span><span style="color: #007700">-</span><span style="color: #0000BB">v&nbsp;</span><span style="color: #007700">/</span><span style="color: #0000BB">etc</span><span style="color: #007700">/</span><span style="color: #0000BB">nginx</span><span style="color: #007700">/</span><span style="color: #0000BB">conf</span><span style="color: #007700">.</span><span style="color: #0000BB">d</span><span style="color: #007700">/</span><span style="color: #0000BB">sites</span><span style="color: #007700">-</span><span style="color: #0000BB">available</span><span style="color: #007700">/</span><span style="color: #0000BB">configuration</span><span style="color: #007700">.</span><span style="color: #0000BB">conf&nbsp;</span><span style="color: #007700">/</span><span style="color: #0000BB">etc</span><span style="color: #007700">/</span><span style="color: #0000BB">nginx</span><span style="color: #007700">/</span><span style="color: #0000BB">conf</span><span style="color: #007700">.</span><span style="color: #0000BB">d</span><span style="color: #007700">/</span><span style="color: #0000BB">sites</span><span style="color: #007700">-</span><span style="color: #0000BB">enabled</span><span style="color: #007700">/</span><span style="color: #0000BB">configuration</span><span style="color: #007700">.</span><span style="color: #0000BB">conf&nbsp;</span><span style="color: #007700">||&nbsp;exit&nbsp;</span><span style="color: #0000BB">1&nbsp;<br /></span></code></div></div></div>
Pretty simple right? This is common practice for a lot of web server configuration file structures.<br />
<br />
<span style="font-weight: bold;"><span style="font-size: large;">3) CONFIGURE PHP</span></span><br />
Using YUM..<br />
<blockquote><cite>Quote:</cite>sudo yum install php-pear-Net-Socket php-pear php-common php-gd php-devel php php-mbstring php-pear-Mail php-cli php-imap php-snmp php-pdo php-xml php-pear-Auth-SASL php-ldap php-pear-Net-SMTP php-mysql</blockquote>
Now make sure it got installed properly..<br />
<blockquote><cite>Quote:</cite>[J@svr1 ~]&#36; php-cgi -v<br />
PHP 5.1.6 (cgi-fcgi) (built: Nov 29 2010 16:43:56)<br />
Copyright &copy; 1997-2006 The PHP Group<br />
Zend Engine v2.1.0, Copyright &copy; 1998-2006 Zend Technologies</blockquote>
<br />
Now you need to add the php_cgi init.d script to get it started properly. I found a decent one on the web, but it had a few flaws, so I took the liberty of modifying it a bit and uploading it to the server. Download/install it using:<br />
<blockquote><cite>Quote:</cite>wget <a href="http://www.adminreference.com/scripts/nginx/php_cgi.txt" target="_blank">http://www.adminreference.com/scripts/nginx/php_cgi.txt</a> -O /etc/init.d/php_cgi<br />
sudo chmod +x /etc/init.d/php_cgi<br />
sudo chkconfig php_cgi on<br />
sudo /etc/init.d/php_cgi start</blockquote>
<br />
If the above fails due to not having spawn-fcgi installed, you can run the following commands to install that as well.<br />
<blockquote><cite>Quote:</cite>wget <a href="http://www.lighttpd.net/download/lighttpd-1.4.18.tar.bz2" target="_blank">http://www.lighttpd.net/download/lighttp...18.tar.bz2</a><br />
tar -xvjf lighttpd-1.4.18.tar.bz2<br />
cd lighttpd-1.4.18/<br />
./configure<br />
make<br />
sudo cp src/spawn-fcgi /usr/bin/spawn-fcgi<br />
sudo +x /usr/bin/spawn-fcgi</blockquote>
<br />
After thats done, you can delete the downloaded content:<br />
<blockquote><cite>Quote:</cite>cd ..<br />
rm -rf lighttpd-1.4.18/<br />
rm lighttpd-1.4.18.tar.bz2</blockquote>
<br />
<span style="font-weight: bold;"><span style="font-size: large;">4) ADD A VHOST</span></span><br />
Heres the configuration file for AR at the time this tutorial was written.<br />
<div class="codeblock phpcodeblock"><div class="title">PHP Code:<br />
</div><div class="body"><div dir="ltr"><code><span style="color: #007700">[</span><span style="color: #0000BB">J</span><span style="color: #007700">@</span><span style="color: #0000BB">svr1&nbsp;</span><span style="color: #007700">~]&#36;&nbsp;</span><span style="color: #0000BB">sudo&nbsp;cat&nbsp;</span><span style="color: #007700">/</span><span style="color: #0000BB">etc</span><span style="color: #007700">/</span><span style="color: #0000BB">nginx</span><span style="color: #007700">/</span><span style="color: #0000BB">conf</span><span style="color: #007700">.</span><span style="color: #0000BB">d</span><span style="color: #007700">/</span><span style="color: #0000BB">sites</span><span style="color: #007700">-</span><span style="color: #0000BB">available</span><span style="color: #007700">/</span><span style="color: #0000BB">adminreference</span><span style="color: #007700">.</span><span style="color: #0000BB">com</span><span style="color: #007700">.</span><span style="color: #0000BB">conf<br /></span><span style="color: #FF8000">#&nbsp;HOST:&nbsp;adminreference.com<br />#&nbsp;DATE:&nbsp;Thu&nbsp;Nov&nbsp;10&nbsp;03:39:15&nbsp;MST&nbsp;2011<br />#<br /><br /></span><span style="color: #0000BB">server&nbsp;</span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">set&nbsp;&#36;domain&nbsp;</span><span style="color: #DD0000">"adminreference.com"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">listen&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;80</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">server_name&nbsp;&nbsp;&#36;domain&nbsp;www</span><span style="color: #007700">.</span><span style="color: #0000BB">&#36;domain</span><span style="color: #007700">;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(&nbsp;</span><span style="color: #0000BB">&#36;host&nbsp;</span><span style="color: #007700">!~&nbsp;</span><span style="color: #DD0000">"^www.(.*)"&nbsp;</span><span style="color: #007700">)&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">rewrite&nbsp;</span><span style="color: #007700">^/(.*)&#36;&nbsp;</span><span style="color: #0000BB">http</span><span style="color: #007700">:</span><span style="color: #FF8000">//www.&#36;domain/&#36;1&nbsp;permanent;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">access_log&nbsp;</span><span style="color: #DD0000">"/www/</span><span style="color: #0000BB">&#36;domain</span><span style="color: #DD0000">/logs/</span><span style="color: #0000BB">&#36;domain</span><span style="color: #DD0000">-access_log"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">#error_log&nbsp;"/www/&#36;domain/logs/&#36;domain-error_log";<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">location&nbsp;</span><span style="color: #007700">/&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">#allow&nbsp;all;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">auth_basic&nbsp;</span><span style="color: #DD0000">"Restricted"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">auth_basic_user_file&nbsp;</span><span style="color: #DD0000">"/www/</span><span style="color: #0000BB">&#36;domain</span><span style="color: #DD0000">/htpasswd"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">root&nbsp;</span><span style="color: #007700">/</span><span style="color: #0000BB">www</span><span style="color: #007700">/</span><span style="color: #0000BB">&#36;domain</span><span style="color: #007700">/</span><span style="color: #0000BB">htdocs</span><span style="color: #007700">/;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">index&nbsp;index</span><span style="color: #007700">.</span><span style="color: #0000BB">php&nbsp;index</span><span style="color: #007700">.</span><span style="color: #0000BB">html&nbsp;index</span><span style="color: #007700">.</span><span style="color: #0000BB">htm</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">location&nbsp;</span><span style="color: #007700">~&nbsp;&#092;.</span><span style="color: #0000BB">php</span><span style="color: #007700">&#36;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">root&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">/</span><span style="color: #0000BB">www</span><span style="color: #007700">/</span><span style="color: #0000BB">&#36;domain</span><span style="color: #007700">/</span><span style="color: #0000BB">htdocs</span><span style="color: #007700">/;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">fastcgi_pass&nbsp;&nbsp;&nbsp;127.0.0.1</span><span style="color: #007700">:</span><span style="color: #0000BB">9000</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">fastcgi_index&nbsp;&nbsp;index</span><span style="color: #007700">.</span><span style="color: #0000BB">php</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">fastcgi_param&nbsp;&nbsp;SCRIPT_FILENAME&nbsp;&nbsp;&#36;document_root&#36;fastcgi_script_name</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;include&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">fastcgi_params</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">location&nbsp;</span><span style="color: #007700">~&nbsp;/&#092;.</span><span style="color: #0000BB">ht&nbsp;</span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">deny&nbsp;all</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />}&nbsp;<br /></span></code></div></div></div>
I like the fact that you can use if statements and set variables in the configuration files makes life so much easier...<br />
<br />
With the above configuration, the new vhost is setup like so..<ul>
<li>Error Log: /www/adminreference.com/logs/adminreference.om-error_log (which is a symlink to /var/log/nginx/adminreference.om-error_log)</li>
<li>Access Log: Same as the error log, only access_log</li>
<li>Restricted access to all .ht* files (.htaccess, .htpasswd, etc)</li>
<li>Setup a 301 redirect from non-www to www</li>
<li>Enabled PHP for the vhost</li>
<li>Set the default pages to index.php index.html index.htm (in that order)</li>
<li>etc, I think you can understand it from the configuration file itself<br />
</li></ul>
<br />
<span style="font-weight: bold;"><span style="font-size: large;">5) DONE!</span></span><br />
Thats pretty much it, you can now test the configurations and reload nginx by running:<br />
<blockquote><cite>Quote:</cite>sudo /etc/init.d/nginx reload</blockquote>
<br />
Now to make life easier, I created a simple bash script that will automatically add a new vhost, you can download it by running:<br />
<blockquote><cite>Quote:</cite>wget <a href="http://www.adminreference.com/scripts/nginx/create_nginx_site.sh.txt" target="_blank">http://www.adminreference.com/scripts/ng...ite.sh.txt</a> -O create_nginx_site.sh</blockquote>
You will also need the template file..<br />
<blockquote><cite>Quote:</cite>wget <a href="http://www.adminreference.com/scripts/nginx/virtualhost.template.txt" target="_blank">http://www.adminreference.com/scripts/ng...mplate.txt</a> -O virtualhost.template</blockquote>
<br />
Heres the sample output:<br />
<blockquote><cite>Quote:</cite>sudo /bin/bash create_nginx_site.sh -h google.com<br />
`/etc/nginx/conf.d/sites-available/virtualhost.template' -&gt; `/etc/nginx/conf.d/sites-available/google.com.conf'<br />
mkdir: created directory `/www/google.com'<br />
mkdir: created directory `/www/google.com/htdocs'<br />
create symbolic link `/www/google.com/logs' to `/var/log/nginx'<br />
changed ownership of `/www/google.com/htdocs/index.php' to nginx:nginx<br />
changed ownership of `/www/google.com/htdocs' to nginx:nginx<br />
changed ownership of `/www/google.com/logs' to nginx:nginx<br />
changed ownership of `/www/google.com' to nginx:nginx<br />
mode of `/www/google.com' retained as 0755 (rwxr-xr-x)<br />
mode of `/www/google.com/htdocs' retained as 0755 (rwxr-xr-x)<br />
mode of `/www/google.com/htdocs/index.php' changed to 0755 (rwxr-xr-x)<br />
neither symbolic link `/www/google.com/logs' nor referent has been changed<br />
changed ownership of `/www/google.com/logs/google.com-access_log' to nginx:nginx<br />
changed ownership of `/www/google.com/logs/google.com-error_log' to nginx:nginx<br />
the configuration file /etc/nginx/nginx.conf syntax is ok<br />
configuration file /etc/nginx/nginx.conf test is successful<br />
Reloading nginx:                                           [  OK  ]<br />
Nginx reloaded! Everyting looks good</blockquote>
The script will..<ul>
<li>Copy/rename the template to the sites-available directory</li>
<li>Create the www directory and htdocs directory</li>
<li>Symlink the logs to /var/log/nginx</li>
<li>Change ownerships to nginx and perms to rwxr-xr-x</li>
<li>Create the access and error log</li>
<li>Create a sample php page for php test (/php.php)</li>
<li>Check the configuration and then reload nginx<br />
</li></ul>
<br />
Thats it! If you run into any bugs, please let me know so I can update the tutorial]]></content:encoded>
		</item>
	</channel>
</rss>
