https://www.nginx.com/resources/wiki/start/topics/tutorials/commandline/
Binary is usualy found at:
/usr/bin/nginx # Or at:
/usr/sbin/nginx
Or find the one that is working:
ps -ef|grep nginx
Service controle:
/etc/init.d/nginx
To test the conf files but not running them:
nginx -t
Stop nginx (Graceful Shutdown):
/usr/bin/nginx -s stop
Or:
kill -QUIT $( cat /usr/local/nginx/logs/nginx.pid )
To apply a command to Nginx:
service nginx <command>
Where <command> could be any of these {start|stop|restart|reload|force-reload|status|configtest|rotate|upgrade}.
Similarly you could use systemctl restart nginx.
Where "service is an "high-level" command used for starting and stopping services in different unixes and linuxes. Depending on the "lower-level" service manager, service redirects on different binaries".
And "systemctl give greater control options".
More here.
Simple http (not https) static server:
server {
server_name _;
listen 80 default_server; # For IPv4.
listen [::]:80 default_server; # For ipV6, where `[::]` is a IPv6 wildcard address.
# The following two lines could be put in the `location /` sub section.
root /var/www/landing;
index index.html;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
}
Here the folder containing the files for the site is /var/www/landing.
Simple https static server:
server {
server_name _;
# Comment the following two lines if you want to disallow the use of http.
listen 80 default_server;
listen [::]:80 default_server;
listen 443 ssl;
listen [::]:443 ssl;
client_max_body_size 50m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_certificate_key /etc/nginx/certificates/{your_domain}.key;
ssl_certificate /etc/nginx/certificates/{your_domain}.pem;
location / {
root /var/www/landing;
index index.html;
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
}
Add this sub part to your server conf to ensure that files ending with a specific extension (here .md) are rendered as text/plain instead of being downloaded:
# Ensure .md files are treated as text/plain.
location ~ \.md$ {
charset utf-8;
types {
text/plain md;
}
# Extra layer of reliability to ensure that all
# clients environments will display the file
# instead of downloading it.
add_header Content-Disposition "inline" always;
}
Add this sub part to your server conf to redirect the request to a program server locally (here on port 3000):
location / {
resolver 127.0.0.11 valid=30s;
set $urlDestination 127.0.0.1:3000;
proxy_pass http://$urlDestination;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header X-Forwarded-Proto $scheme;
}
Replace this with the static version from the examples above such as something like this:
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
Add the following on top of your TLS conf to redirect any http to https (yes you should have two server {} sub section then):
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
location / {
return 301 https://$host$request_uri;
}
}
More about configuration files.
Default both access and error logs can be found under /var/log/nginx.
Good doc on logs with Nginx.
- Default logs positions.
- Various default conf files in addition of the sites' specific ones (default enabled, general conf, nginx conf, yes 3 of them, which does not include the conf for sites).
/etc/nginx/nginx.conf: configuration among all others. A conf file set insites-enabledis just merely overiding this one parameter by parameter.
/etc/nginx/conf.d/: Could be used to put files splited by features. Then later included in a conf as such :
include conf.d/http;
include conf.d/stream;
include conf.d/exchange-enhanced;
- Be able to update projects from git webhooks.
- Be able to render Markdown when asking for a
.mdfile. But output it raw if asked likemyfile.md?raw. - Be able to share tmp projects.