Nginx: Difference between revisions
| Line 16: | Line 16: | ||
== Configuration == | == Configuration == | ||
You may want to make backup of original nginx.conf file before writting your own | |||
{{Cmd|mv /etc/nginx/nginx.conf /etc/nginx/nginx.conf.orig}} | |||
Configuring Nginx to listen to port 80 and process .html or .htm files | Configuring Nginx to listen to port 80 and process .html or .htm files | ||
{{Cmd| | {{Cmd|vi /etc/nginx/nginx.conf}} | ||
<pre> | <pre> | ||
user www; | user www; | ||
Revision as of 06:52, 22 November 2016
Nginx (engine x) is an HTTP and reverse proxy server, a mail proxy server, and a generic TCP/UDP proxy server
Installation
Nginx package is available in the Alpine Linux repositories. To install it run:
apk add nginx
Creating new user and group 'www' for nginx
adduser -D -u 1000 -g 'www' www
Create a directory for html files
mkdir /www chown -R www:www /var/lib/nginx chown -R www:www /www
Configuration
You may want to make backup of original nginx.conf file before writting your own
mv /etc/nginx/nginx.conf /etc/nginx/nginx.conf.orig
Configuring Nginx to listen to port 80 and process .html or .htm files
vi /etc/nginx/nginx.conf
user www;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
sendfile on;
access_log /var/log/nginx/access.log;
keepalive_timeout 3000;
server {
listen 80;
root /www;
index index.html index.htm;
server_name localhost;
client_max_body_size 32m;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/lib/nginx/html;
}
}
}
Sample page
vim /www/index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>HTML5</title>
</head>
<body>
Server is online
</body>
</html>
Controlling nginx
Start Nginx
After the installation Nginx is not running. To start Nginx, use start.
rc-service nginx start
You will get a feedback about the status.
* /run/nginx: creating directory * /run/nginx: correcting owner [ ok ] * Starting nginx ... [ ok ]
Restart Nginx
After changing the configuration file nginx needs to be restarted. If you want to restart the web server use restart.
rc-service nginx restart
Stop Nginx
If you want to stop the web server use stop.
rc-service nginx stop
Runlevel
Normally you want to start the web server when the system is launching. This is done by adding nginx to the needed runlevel.
rc-update add nginx default
Testing Nginx
This section is assuming that nginx is running and sample html page "/www/index.html" is created. Launch a web browser and point it to your web server. You should get:
Server is online