Nginx: Difference between revisions
From charlesreid1
| Line 57: | Line 57: | ||
The contents: | The contents: | ||
'''example.com config file''' | |||
<pre> | <pre> | ||
/etc/nginx/sites-available/example.com | |||
example.com | |||
-------------------------- | -------------------------- | ||
| Line 76: | Line 78: | ||
} | } | ||
} | } | ||
</pre> | |||
test.com config file | '''test.com config file''' | ||
<pre> | |||
/etc/nginx/sites-available/test.com | |||
-------------------------- | -------------------------- | ||
server { | server { | ||
| Line 92: | Line 99: | ||
} | } | ||
} | } | ||
</pre> | |||
==Enabling Site/Site Config== | |||
To enable the site whose config files we just created, we create symlinks in nginx's sites-enabled: | |||
<pre> | |||
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/ | |||
sudo ln -s /etc/nginx/sites-available/test.com /etc/nginx/sites-enabled/ | |||
</pre> | </pre> | ||
Revision as of 22:48, 29 March 2015
I finally got fed up with Apache's endless permissions problems and incomprehensible labyrinth of config files and virtualhosts that never, ever work, ever, not even a single time.
I switched to nginx.
Installing
Ubuntu
sudo apt-get install nginx
Basic Info
By default, nginx serves files out of
/usr/share/nginx/html
The default config file is located in
/etc/nginx/sites-available/default
Virtual Hosts
Directory Structure and Permissions
I have created two http root directories, to serve two virtual hosts:
/www/example.com/public_html/ /www/test.com/public_html/
Both contain an index.html file with a simple hello world message.
Now I transfer ownership of these two directories to my regular username,
sudo chown -R $USER:$USER /www/example.com/public_html sudo chown -R $USER:$USER /www/test.com/public_html sudo chmod -R 755 /www/
Config File
Create a copy of the config file for each site:
sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/example.com sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/test.com
The contents:
example.com config file
/etc/nginx/sites-available/example.com
--------------------------
server {
listen 80;
listen [::]:80;
root /www/example.com/public_html;
index index.html index.htm;
server_name example.com www.example.com;
location / {
try_files $uri $uri/ =404;
}
}
test.com config file
/etc/nginx/sites-available/test.com
--------------------------
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /www/test.com/public_html;
index index.html index.htm;
server_name test.com www.test.com;
location / {
try_files $uri $uri/ =404;
}
}
Enabling Site/Site Config
To enable the site whose config files we just created, we create symlinks in nginx's sites-enabled:
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/ sudo ln -s /etc/nginx/sites-available/test.com /etc/nginx/sites-enabled/