Tech:Nginx

NGINX is a high performance web server which Miraheze uses for all of our services that use HTTP.

Adding a new site
Adding a new site to NGINX is relatively easy but also depends on what you want to do.

New Site
To add a new site you add a .conf file in  and then symlink

With the contents:

(This redirects from domain a to domain b)

server { listen 80; listen [::]:80; listen 443 ssl http2; listen [::]:443 ssl http2;

server_name ; root ;

ssl_certificate ; ssl_certificate_key ;

ssl_trusted_certificate /etc/ssl/certs/GlobalSign.crt; # path to trusted certificate

add_header Strict-Transport-Security "max-age=2419200";

location / { rewrite ^(.*)$ https:// $1; } }

Debugging
Debugging NGINX can be configured in multiple ways.

Syntax Checking
To check nginx syntax you run:

Which tells you if the syntax passes.

Access Logs
The access logs are useful to tell you either if someone is causing huge traffic to the site or which url is failing.

You can view the access log at:

Error Log
The error log is located at by default:

You can configure the error log to include debugging information by doing:

Debugging DDOS
You can do the following:

Which will print the most frequent ip and how many times it's listed. This will give you an indicator if someone is abusing the resources.

You can also cat the access log (or varnish log) to see if there's a pattern (e.g a specific url showing up more then once, or user agent).