2018-07-03 01:27:39 +00:00
# Templates
These NGINX configurations set up HTTP servers at port 80. HTTPS on port 443 should be set up using [certbot ](https://www.nginx.com/blog/using-free-ssltls-certificates-from-lets-encrypt-with-nginx/ ).
## Static web page
2021-05-15 06:44:57 +00:00
The URL [example.space ](http://example.space ) will point to files in `/srv/www/example.space` .
2018-07-03 01:27:39 +00:00
```nginx
server {
listen 80;
listen [::]:80;
2021-05-15 06:44:57 +00:00
root /srv/www/example.space;
server_name example.space;
2018-07-03 01:27:39 +00:00
error_page 404 /404.html;
location / {
try_files $uri $uri/ =404;
}
}
```
2021-05-15 06:44:57 +00:00
## Reverse proxy
The URL [example.space ](http://example.space ) will point to the local [port 8080 ](http://localhost:8080 ).
```nginx
server {
listen 80;
listen [::]:80;
client_max_body_size 512M;
server_name example.space;
location / {
proxy_pass http://localhost:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
```
2018-07-03 01:27:39 +00:00
## PHP site with HTTP authentication
2021-05-15 06:44:57 +00:00
The URL [example.space ](http://example.space ) will point to the PHP application at `/srv/www/example.space/index.php` . HTTP authentication done as indicated [here ](https://docs.nginx.com/nginx/admin-guide/security-controls/configuring-http-basic-authentication/ ).
2018-07-03 01:27:39 +00:00
```nginx
server {
listen 80;
listen [::]:80;
2021-05-15 06:44:57 +00:00
server_name example.space;
2018-07-03 01:27:39 +00:00
2021-05-15 06:44:57 +00:00
root /srv/www/example.space;
2018-07-03 01:27:39 +00:00
index index.html index.php;
# set up HTTP basic authentication
auth_basic "Authentication Required";
auth_basic_user_file /etc/apache2/.htpasswd;
location / {
try_files $uri $uri/ =404;
}
# process PHP requests
location ~ \.php$ {
include snippets/fastcgi-php.conf;
2021-05-15 06:44:57 +00:00
fastcgi_pass unix:/var/run/php/php-fpm.sock;
2018-07-03 01:27:39 +00:00
}
location ~ /\.ht {
deny all;
}
}
```