You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
86 lines
3.9 KiB
HTML
86 lines
3.9 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<meta name="description" content="A guide to setting up an nginx website pointed at a domain/subdomain">
|
|
<meta name="keywords" content="Blog, articles, NGINX, web server, guide, website">
|
|
<meta name="author" content="Nathan (Aney) Steel">
|
|
<meta name="theme-color" content="white">
|
|
<meta name="theme-color" content="black">
|
|
<link rel="stylesheet" type="text/css" href="/main.css">
|
|
<link rel="icon" type="image/png" href="/images/favicon.svg">
|
|
<title>How to setup an NGINX website</title>
|
|
</head>
|
|
|
|
<body>
|
|
<header>
|
|
<h1>How to setup an NGINX website</h1>
|
|
<input id="burger-toggle" type="checkbox"/>
|
|
<label class="burger-container" for="burger-toggle"><div class="burger"></div></label>
|
|
<hr/>
|
|
<nav>
|
|
<a href="/">home</a>
|
|
<a href="/equipment.html">equipment</a>
|
|
<a href="/projects.html">projects</a>
|
|
<a href="/blog/">blog</a>
|
|
<a href="/sitemap.html">misc</a>
|
|
<a href="/support.html">support</a>
|
|
</nav>
|
|
<hr/>
|
|
</header>
|
|
|
|
<main>
|
|
<section>
|
|
<p>Nginx has the ability to host multiple websites, all at different domains/sub-domains. This guide will show you how to point a domain at the server, and display a different website than the default NGINX page.</p>
|
|
<h2>Make the domain point to the server</h2>
|
|
<p>In your domains DNS records ensure that the domain/sub-domain is pointing to the servers IP address, otherwise NGINX won't get told to serve the website</p>
|
|
|
|
<h2>Create the website directory</h2>
|
|
<p>We need to create a directory for the website to live, and add a basic webpage to it. Websites typically live in <strong>/var/www/</strong> but sometimes in users home directories, or elsewhere. We'll stick with the former</p>
|
|
|
|
<h2>Change directory permissions to www-user</h2>
|
|
<p>Nginx's default group is www-user, so to serve the website we'll grant permissions to www-user</p>
|
|
<h3>Add user account to www-user</h3>
|
|
<p>Make it easier...</p>
|
|
|
|
<h2>Create an nginx site config</h2>
|
|
<p>To get nginx to check the domain, and return the correct website, we need to configure it to do so</p>
|
|
<p>Create a file in</p>
|
|
<pre><code>/etc/nginx/sites-available/<DOMAIN-NAME></code></pre>
|
|
<p>Containing the contents below. This will set the server to listen on port 80 (http) for any requests from the domain name set. It will then direct the root domain to the directory in root, and set the index page the file index.html, or index.htm if the former wasn't found</p>
|
|
<pre><code>server {
|
|
listen 80 default ;
|
|
listen [::]:80 ;
|
|
server_name <DOMAIN-NAME> ;
|
|
|
|
location / {
|
|
root /var/www/<DOMAIN-NAME> ;
|
|
index index.html index.htm ;
|
|
}</code></pre>
|
|
<h3>Create a symlink to sites-enables</h3>
|
|
<p>Now to get nginx to check this config we'll need to symlink it to from sites-available, to sites-enabled</p>
|
|
<pre><code>sudo ln -s /etc/nginx/sites-available/<DOMAIN-NAME> /etc/nginx/sites-enabled/</code></pre>
|
|
<h3>Reload nginx</h3>
|
|
<pre><code>sudo systemctl reload nginx</code></pre>
|
|
<p>If the above command fails, you can check your nginx config for errors with</p>
|
|
<pre><code>sudo nginx -t</code></pre>
|
|
<p>Then once any errors have been fixed, reload nginx again, and it should be good to go</p>
|
|
|
|
<h2>Add a basic webpage</h2>
|
|
<p>So we can tell the config is working, we'll add a basic webpage.</p>
|
|
|
|
<h2>Check the website</h2>
|
|
<p>In your browser enter the domain name we've just setup in nginx, and you'll see that the basic HTML page we've created is being displayed</p>
|
|
|
|
</section>
|
|
</main>
|
|
|
|
<footer>
|
|
<hr/>
|
|
<p>Written by <a href="http://aney.co.uk" target="_blank" rel="noopener">@aney</a> with <a href="https://danluu.com/web-bloat/" target="_blank" rel="noopener">web bloat</a> in mind | <a href="https://github.com/Aney/website" target="_blank" rel="noopener">Source Code</a></p>
|
|
</footer>
|
|
</body>
|
|
</html>
|
|
|