nginx Configuration Template
For more information about nginx, please refer to the official documentation.
* Modify this template according to your settings before starting the service!
To download the file, use the following command:
curl -O "https://gitflic.ru/project/kovalevaa/utils/blob/raw?file=nginx/mytest.site.ru"
File: mytest.site.ru
mytest.site.ru
server {
server_name mytest.site.ru;
client_max_body_size 10G;
location / {
proxy_pass http://127.0.0.1:8080;
proxy_read_timeout 3600s;
proxy_send_timeout 3600s;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Ssl "ON";
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_redirect off;
proxy_buffering off;
proxy_http_version 1.1;
}
listen 443 ssl;
ssl_certificate /etc/ssl/certs/mytest.site.ru/fullchain.pem;
ssl_certificate_key /etc/ssl/private/mytest.site.ru/privkey.pem;
}
server {
if ($host = mytest.site.ru) {
return 301 https://$host$request_uri;
}
listen 80;
server_name mytest.site.ru;
return 404;
}
Quick Guide to Working with nginx
By default, nginx site configuration files are located in:
/etc/nginx/sites-available
- All available configuration files
/etc/nginx/sites-enabled
- Currently active configuration files
Best practices:
- Name configuration files after their respective domains (e.g., mytest.site.ru
or mytest.site.ru.conf
)
- Store all configuration files in /etc/nginx/sites-available
- To enable a configuration, create a symbolic link to /etc/nginx/sites-enabled
:
ln -s /etc/nginx/sites-available/mytest.site.ru /etc/nginx/sites-enabled
- Before restarting nginx, verify configuration syntax:
nginx -t
- To apply changes, restart/reload the nginx service
Template Overview
server {}
- Backend server configuration block
- listen
- Port to listen on
- server_name
- Hostname to serve
- ssl_certificate
- Path to SSL certificate file
- ssl_certificate_key
- Path to private key file
- include
- Directive to import settings from another file
location / {}
- Proxy configuration block (/
handles all incoming requests)
- proxy_pass
- Upstream server address
- proxy_read_timeout
, proxy_send_timeout
- Timeout settings
- proxy_set_header
- Request header modifications
- proxy_redirect
- Controls Location header rewriting
- proxy_buffering
- Buffering configuration
- proxy_http_version
- HTTP protocol version
Automatic translation!
This page has been automatically translated. The text may contain inaccuracies.