Nginx Configuration¶
To configure nginx, the following template can be used:
Default nginx.conf¶
The dist configuration shipped with nginx looks similar to the following:
nginx.conf¶
Save a coy of this to ‘$HOME/.local/etc/nginx/nginx.conf’
~/documentation $ mkdir -p $HOME/.local/etc/nginx
~/documentation $ $EDITOR $HOME/.local/etc/nginx/nginx.conf
or alternatively, copy the entire nginx dist configuration
~/documentation $ cp -R /etc/nginx $HOME/.local/etc
Local nginx dev configuration¶
Add the prefix ‘$HOME/.local’ to all the lines starting with $HOME (expanding $HOME to your full path):
In the http block, add the following:
… and in the server block, change the port from 80 to 8181
Check dev-conf¶
Make sure the configuration is syntactically correct:
nginx -t \
-c $HOME/.local/etc/nginx/nginx.conf \
-e $HOME/.local/var/log/nginx/error_log
nginx options¶
From nginx -h
nginx version: nginx/1.21.6 Usage: nginx [-?hvVtTq] [-s signal] [-p prefix] [-e filename] [-c filename] [-g directives]
- Options:
- -?,
-h : this help
- -v
version and exit
- -V
: show version and configure options then exit
- -t
: test configuration and exit
- -T
: test configuration, dump it and exit
- -q
: suppress non-error messages during configuration testing
- -s signal
: send signal to a master process: stop, quit, reopen, reload
- -p prefix
: set prefix path (default: /usr/)
- -e filename
: set error log file (default: /var/log/nginx/error_log)
- -c filename
: set configuration file (default: /etc/nginx/nginx.conf)
- -g directives
: set global directives out of configuration file
Remove user and group¶
As this will be a local user running the server, the user directive needs to be removed.
This is used when root launches the process to hand control over to the named user/group.
Add root location¶
Add the following the to server block
root $HOME/git/documentation/build/html;
Making nginx log directories¶
~/documentation $ mkdir -p $HOME/.local/var/log/nginx
Run nginx dev docs¶
To run the server and view the documentation:
~/documentation $ nginx -c ~/.local/etc/nginx/nginx.conf \
-e $HOME/.local/var/log/nginx/error_log
~/documentation $ xdg-open http://localhost:8181
Create an nginx-dev alias¶
To make launching the server easier, the following can be added ‘$HOME/.bashrc’
~/documentation $ printf "
alias nginx-dev=\"nginx\"\\
\" -c \$HOME/.local/etc/nginx/nginx.conf\"\\
\" -e \$HOME/.local/var/log/nginx/error_log\"
" >> $HOME/.bashrc
Then to launch the server, the following can be used:
~/documentation $ nginx-dev
Obtaining the ‘$HOME’ value¶
~/documentation $ echo $HOME
/home/..