update nach VL http/webserver

This commit is contained in:
bpetschowitsch
2026-04-10 13:19:27 +02:00
parent a0c327413b
commit 168b213166
4 changed files with 176 additions and 0 deletions
+80
View File
@@ -0,0 +1,80 @@
# Nginx Intro
The main folder of nginx is found under:
```text
/etc/nginx
```
Check the complete folder structure (incl. subfolders):
```bash
sudo apt install tree
tree /etc/nginx/
```
## nginx.conf
* This is the main configuration file. It includes settings like logging, configuration of worker-processes and includes other configuration files.
* This is the first read configuration file (from top to bottom).
* Files included via `include`, are inserted at the location of the directive.
* The scope of settings can either be: `http`, `server`, `location` (wide to narrow). Some settings are allowed at multiple scope level. A similair pattern applies for sites that can be general (all domains), or more narrow (specific domain). Settings in a narrow scope overwrite settings in a wider scope.
* conflicting settings within the same scope are rejected, sometimes ignored (sanity check on startup). But anyhow those conflicts can be identified via `nginx -t`.
## conf.d
Folder for configuration files. All files ending with `.conf` are automatically loaded by nginx.
Allows better structure and delegations.
## sites-available
Used for site (domain) specific configuration files (virtual hosting). Configurations in `sites-available` are **ignored** by nginx.
## sites-enabled
Used to enable the sites defined in `sites-available`. It should contain only symlinks.
## modules-available and modules-enabled
Used for nginx modules (extensions).
## Configuration structure
Nginx uses following hierachical structure:
```nginx
# --- main context (global) ---
user nginx;
worker_processes auto;
events {
# --- event-context ---
worker_connections 1024;
}
http {
# --- HTTP-context (Webserver-Settings) ---
include /etc/nginx/mime.types;
server {
# --- server-context (Virtual Host / Website) ---
listen 80;
server_name example.com;
root /var/www/example.com;
location / {
# --- location-context (URL-Handling) ---
try_files $uri $uri/ =404;
}
}
}
```
# Document-Root
per default the document-root is defined (in nginx.conf) under:
```text
/var/www/html/
```
Best-practice to generate a custom-directory within `/var/www/` per domain. E.g. the website `example.com` would be:
`/var/www/example.com/`
# Logging
default folder for nginx log files is:
```text
/var/log/nginx/
```
+96
View File
@@ -0,0 +1,96 @@
# hello world
instruction to prepare nginx site configuration
## nginx site configuration
the site configuration is created within `/etc/nginx/sites-available/`
```bash
cd /etc/nginx/sites-available
```
create a new file for the domain...or easier, copy the exisiting one:
```bash
sudo cp default *my_domain*
```
and edit the file:
```bash
sudo vi *my_domain*
```
```nginx
server {
listen 80;
listen [::]:80;
server_name *my_domain*;
root /var/www/*my_domain*/;
index index.html index.htm index.nginx-debian.html;
location / {
try_files $uri $uri/ =404;
}
}
```
## folder structure
change to directory `/var/www/`:
```bash
cd /var/www/
```
and create a subfolder for the own domain/website:
```bash
sudo mkdir /var/www/*my_domain*
sudo chown www-data:www-data /var/www/*my_domain*
```
## create hello-world index.html
```bash
sudo vi /var/www/*my_domain*/index.html
```
```html
<html>
<head>
<title>Welcome!</title>
</head>
<body>
<h1>Hello World!</h1>
</body>
</html>
```
```bash
sudo chown www-data:www-data index.html
```
## enable, verify and restart
enable the new site:
```bash
sudo ln -s /etc/nginx/sites-available/*my_domain* /etc/nginx/sites-enabled/*my_domain*
```
validate configuration:
```bash
sudo nginx -t
```
restart nginx:
```bash
sudo systemctl restart nginx
```