start:software:nginx
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
start:software:nginx [2024/08/26 23:20] – marlonivo | start:software:nginx [Unknown date] (current) – removed - external edit (Unknown date) 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ===== Setting Up an NginX Web-and Mailserver ===== | ||
- | **Important: | ||
- | |||
- | Exchange yourdomain.xyz with your actual domain! | ||
- | |||
- | Exchange yoursite with the actual name of your site! | ||
- | |||
- | **Preparations: | ||
- | |||
- | - Search for a cheap Website Hoster (i use Hetzner, alternatives are Linode and Vultr) | ||
- | - Create an Account | ||
- | - Get the cheapest cloud server which runs Debian on it (you can upgrade the Power and Storage later when your Website has actual traffic) | ||
- | |||
- | **Domain: | ||
- | - Choose any DNR you want (i use njalla, because no personal data is required there) | ||
- | - Create an Account and buy your wished Domain (.xyz endings are pretty cheap, can recommend) | ||
- | - Edit the DNS Records so that they point to your Server: | ||
- | |||
- | > DNS resolution involves converting a host name, e.g. www.example.com, | ||
- | |||
- | This is how to edit your DNS Records on the Server to redirect to your yourdomain. | ||
- | |||
- | | **Type** | ||
- | | A (IPV4) | ||
- | | A (IPV4) | ||
- | | A (IPV4) | ||
- | | AAAA (IPV6)| www | your IPV6 Adress | 5m | | ||
- | | AAAA (IPV6)| @ | your IPV6 Adress | 5m | | ||
- | | AAAA (IPV6)| * | your IPV6 Adress | 5m | | ||
- | |||
- | |||
- | ---- | ||
- | |||
- | ==== Logging into the Server ==== | ||
- | |||
- | We first want to log into our Server. Therefore pull up a terminal and type (*Note you can also replace the yourdomain.xyz with the IP address of your server): | ||
- | |||
- | < | ||
- | ssh root@yourdomain.xyz | ||
- | </ | ||
- | |||
- | |||
- | ==== Installing the Webserver Nginx ==== | ||
- | |||
- | |||
- | If the program runs without an error, ssh has now logged you into your server. Let's start by running the following commands. | ||
- | |||
- | < | ||
- | apt update | ||
- | apt upgrade | ||
- | apt install nginx | ||
- | </ | ||
- | |||
- | The first command checks for packages that can be updated and the second command installs any updates. | ||
- | |||
- | The third command installs nginx (pronounced Engine-X), which is the web server we'll be using, along with some other programs. | ||
- | |||
- | |||
- | ==== Configuring the Webserver Nginx ==== | ||
- | |||
- | Nginx is your webserver. You can make a little website or page, put it on your VPS and then tell nginx where it is and how to host it on the internet. It's simple. Let's do it. | ||
- | |||
- | Info: | ||
- | Nginx configuration files are in / | ||
- | |||
- | Create a file in / | ||
- | |||
- | < | ||
- | nano / | ||
- | </ | ||
- | |||
- | Note: | ||
- | " | ||
- | |||
- | Add the following content to the file. | ||
- | |||
- | < | ||
- | server { | ||
- | listen 80 ; | ||
- | listen [::]:80 ; | ||
- | server_name yourdomain.xyz ; | ||
- | root / | ||
- | index index.html index.htm index.nginx-debian.html ; | ||
- | location / { | ||
- | try_files $uri $uri/ =404 ; | ||
- | } | ||
- | } | ||
- | </ | ||
- | |||
- | If you want to hide .html on your domain-endings (https:// | ||
- | |||
- | < | ||
- | location / { | ||
- | if ($request_uri ~ ^/ | ||
- | return 302 /$1; | ||
- | } | ||
- | try_files $uri $uri.html $uri/ =404; | ||
- | } | ||
- | </ | ||
- | |||
- | **Explanation of those settings:** | ||
- | |||
- | The **listen** lines tell nginx to listen for connections on both IPv4 and IPv6. | ||
- | |||
- | The **server_name** is the website that we are looking for. By putting yourdomain.xyz here, whenever someone connects to this server and is looking for that address, they will be directed to the content in this block. | ||
- | |||
- | **root** specifies the directory we're going to put our website files in. This can theoretically be wherever, but it is conventional to have them in /var/www/. Name the directory in that whatever you want. | ||
- | |||
- | **index** determine what the " | ||
- | |||
- | Lastly, the **location** block is really just telling the server how to look up files, otherwise throw a 404 error. Location settings are very powerful, but this is all we need them for now. | ||
- | Create the directory and index for the site | ||
- | |||
- | We'll actually start making a " | ||
- | |||
- | < | ||
- | mkdir / | ||
- | </ | ||
- | |||
- | Now let's create an index.html file inside of that directory, which will appear when the website is accessed: | ||
- | |||
- | < | ||
- | nano / | ||
- | </ | ||
- | |||
- | I'll add the following basic content, but you can add whatever you want. This will appear on your website. | ||
- | |||
- | <code html> | ||
- | < | ||
- | < | ||
- | < | ||
- | < | ||
- | </ | ||
- | |||
- | ==== Enable the site ==== | ||
- | |||
- | Once you save that file, we can enable it making a link to it in the sites-enabled directory: | ||
- | |||
- | < | ||
- | ln -s / | ||
- | </ | ||
- | |||
- | Now we can just reload or restart to make nginx service the new configuration: | ||
- | |||
- | < | ||
- | systemctl reload nginx | ||
- | </ | ||
- | |||
- | You can now visit your up and running webpage. | ||
- | |||
- | ==== Encrypt your Site ==== | ||
- | In order to get the green official certified Page Symbol (everyone wants) we need to install a certification bot, therefore type: | ||
- | |||
- | < | ||
- | apt-install python3-certbot-nginx | ||
- | </ | ||
- | |||
- | After the installationprocess is finished you just have to type in the following command. Press enter and choose the domain' | ||
- | |||
- | < | ||
- | cerbot --nginx | ||
- | </ | ||
- | |||
- | |||
- | {{: | ||
- | |||
- | |||
- | ==== Pushing and Pulling your Website Files ==== | ||
- | |||
- | This part will be a repetetive task (feel free to automate it with a script). In order to upload your local files (from the device you are using to read this guide), you need to install rsync. | ||
- | |||
- | < | ||
- | rsync -vrP --delete-after ~/ | ||
- | </ | ||
- | |||
- | Now we are finished, the website should update automatically immeadietly after you synced your files via rsync (no need to restart the server). | ||
- | |||
- | ==== Contribution ==== | ||
- | * [[https:// |
start/software/nginx.1724714434.txt.gz · Last modified: by marlonivo