From 98ae91447d2f29640094398068cca1a884f46d9b Mon Sep 17 00:00:00 2001
From: Silvino Silva Remove nginx user or group, system defines www user and group; Add user nginx to www group; Change default home directory of www user; Change default home directory of nginx user; Create configuration directory's for better organization; Directories should have 644 or 664 and
- files chmod 755 or 775; Certificates allow a more secure connection. Lets create
self-signed certificate; Create private key; Having password is a good idea, but requires it every
time nginx is restarted. To remove; Read nginx pitfalls,
for more information about optimization
digitalocean,
Number of worker_processes must be equal or less than
- the number of available cpu cores1. Nginx
+ Nginx
- 1.1. Install Nginx
+ 1. Install Nginx
$ prt-get depinst nginx
@@ -21,17 +21,16 @@
UID=xxxxx-xxx-xxx-xxx-xxxxxxxx /srv/www ext4 defaults,nosuid,noexec,nodev,noatime 1 2
-
- # userdel nginx
- # groupdel nginx
+ # usermod -a -G www nginx
-
- # usermod -m -d /srv/www www
+ # usermod -m -d /srv/www nginx
1.2. Logs
-
-
- $ sudo grep "login" /var/log/nginx/access.log
- $ sudo grep "etc/passwd" /var/log/nginx/access.log
- $ sudo egrep -i "denied|error|warn" /var/log/nginx/error.log
-
-
- 1.3. User Directory
-
-
-
-
- location ~ ^/~(.+?)(/.*)?$ {
- alias /home/$1/public_html$2;
- index index.html index.htm;
- autoindex on;
- }
-
-
-
- $ sudo find . -type f -print0 | xargs -0 chmod 644
- $ sudo find . -type d -print0 | xargs -0 chmod 755
-
-
- 1.4. Certificates
+ 2. Certificates
- $ sudo mkdir /etc/nginx/ssl
- $ sudo cd /etc/nginx/ssl
-
-
@@ -112,7 +78,7 @@
Locality Name (eg, city) []:
Organization Name (eg, company) [Internet Widgits Pty Ltd]:
Organizational Unit Name (eg, section) []:
- Common Name (e.g. server FQDN or YOUR name) []:c13.nark.biz.tm
+ Common Name (e.g. server FQDN or YOUR name) []:core.privat-network.net
Email Address []:
Please enter the following 'extra' attributes
@@ -127,33 +93,31 @@
$ sudo openssl x509 -req -days 365 -in /etc/ssl/certs/nginx.csr -signkey /etc/ssl/keys/nginx.key -out /etc/ssl/certs/nginx.crt
Signature ok
- subject=/C=PT/ST=Porto/O=Internet Widgits Pty Ltd/CN=c13.nark.biz.tm
+ subject=/C=PT/ST=Porto/O=Internet Widgits Pty Ltd/CN=core.privat-network.net
Getting Private key
Enter pass phrase for /etc/ssl/keys/nginx.key:
$
- Remove Password
-
- $ sudo cp /etc/ssl/keys/nginx.key /etc/ssl/keys/nginx.key.org
- $ sudo openssl rsa -in /etc/ssl/keys/nginx.key.org -out /etc/ssl/keys/nginx.key
+ $ sudo cp /etc/ssl/keys/nginx.key /etc/ssl/keys/nginx.key.pass
+ $ sudo openssl rsa -in /etc/ssl/keys/nginx.key.pass -out /etc/ssl/keys/nginx.key
Enter pass phrase for /etc/ssl/keys/nginx.key.org:
writing RSA key
$
- 1.5. Nginx Configuration
+ 3. Nginx Configuration
-
$ nproc
@@ -172,32 +136,26 @@
#
- # /etc/nginx/nginx.conf
+ # /etc/nginx/nginx.conf - nginx server configuration
#
- user www;
- worker_processes 2;
- error_log /var/log/nginx/error.log info;
+ user nginx;
+ worker_processes auto;
+
+ error_log /var/log/nginx/error.log;
+
+ pid /var/run/nginx.pid;
+
events {
worker_connections 1024;
}
- http {
-
- include /etc/nginx/mime.types;
- default_type application/octet-stream;
-
- sendfile on;
- #tcp_nopush on;
- #keepalive_timeout 620;
- keepalive_timeout 65;
- client_body_timeout 12;
- client_header_timeout 12;
- # send_timeout 620;
- send_timeout 65;
+ http {
+ include mime.types;
+ default_type application/octet-stream;
##
# SSL Settings
@@ -209,25 +167,25 @@
ssl_certificate /etc/ssl/certs/nginx.crt;
ssl_certificate_key /etc/ssl/keys/nginx.key;
- ##
- # Logging Settings
- ##
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
- access_log /var/log/nginx/access.log combined;
- error_log /var/log/nginx/error.log;
+ access_log /var/log/nginx/access.log;
+ error_log /var/log/nginx/error.log
- ##
- # Gzip Settings
- ##
+ sendfile on;
+ #tcp_nopush on;
+
+ keepalive_timeout 65;
+ client_body_timeout 12;
+ client_header_timeout 12;
+ send_timeout 65;
- gzip on;
- gzip_disable "msie6";
+ gzip on;
gzip_vary on;
- gzip_proxied any;
+ #gzip_proxied any;
gzip_comp_level 9;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
@@ -245,40 +203,44 @@
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*.conf;
+
}
- # End of file
+ # End of file
+
- Check /etc/nginx/sites + for more examples.
-Install php and setup php.ini as development mode;
- $ prt-get depinst php php-fpm php-gd php-pdo-pgsql composer
+ $ prt-get depinst php php-fpm php-gd
Setup php ini in development mode;
- $ sudo cp /etc/php/php.ini-development php.ini + $ sudo cp /etc/php/php.ini-development /etc/php/php.ini ++ +
$ php --ini
Configuration File (php.ini) Path: /etc/php
Loaded Configuration File: /etc/php/php.ini
Scan for additional .ini files in: /etc/php/conf.d
Additional .ini files parsed: /etc/php/conf.d/extensions.ini,
/etc/php/conf.d/pdo_pgsql.ini
-
- $
- Server (virtual host) with Laravel, - /etc/nginx/sites/laravel.conf;
+ /etc/nginx/sites/laravel.conf;
server {
@@ -286,7 +248,7 @@
listen [::]:443 ssl;
root /srv/www/atom/public;
- server_name c13.nark.biz.tm;
+ server_name core.privat-network.net;
index index.html index.htm index.php;
charset utf-8;
@@ -299,7 +261,7 @@
location = /robots.txt { access_log off; log_not_found off; }
access_log off;
- error_log /var/log/nginx/c13-nark-biz-tm-error.log error;
+ error_log /var/log/nginx/core.privat-network.net-error.log error;
sendfile off;
@@ -322,6 +284,35 @@
}
+
+ location ~ ^/~(.+?)(/.*)?$ {
+ alias /home/$1/public_html$2;
+ index index.html index.htm;
+ autoindex on;
+ }
+
+
+ Directories should have 644 or 664 and + files chmod 755 or 775;
+ ++ $ sudo find . -type f -print0 | xargs -0 chmod 644 + $ sudo find . -type d -print0 | xargs -0 chmod 755 ++ +
+ $ sudo grep "login" /var/log/nginx/access.log + $ sudo grep "etc/passwd" /var/log/nginx/access.log + $ sudo egrep -i "denied|error|warn" /var/log/nginx/error.log ++ + Tools Index
This is part of the c9-doc Manual.
--
cgit
From 84221a7bb9bcdac6a3c162e77c2191a1c44bf574 Mon Sep 17 00:00:00 2001
From: Silvino Silva Sign SSL cetificate; Having password is a good idea, but requires it every
@@ -105,9 +108,11 @@
- $ sudo openssl x509 -req -days 365 -in /etc/ssl/certs/nginx.csr -signkey /etc/ssl/keys/nginx.key -out /etc/ssl/certs/nginx.crt
+ $ sudo openssl x509 -req -days 365 \
+ -in /etc/ssl/certs/nginx.csr \
+ -signkey /etc/ssl/keys/nginx.key \
+ -out /etc/ssl/certs/nginx.crt
+
Signature ok
- subject=/C=PT/ST=Porto/O=Internet Widgits Pty Ltd/CN=core.privat-network.net
+ subject=/C=PT/ST=Some-State/O=Internet Widgits Pty Ltd/CN=core.privat-network.net
Getting Private key
Enter pass phrase for /etc/ssl/keys/nginx.key:
- $
$ sudo cp /etc/ssl/keys/nginx.key /etc/ssl/keys/nginx.key.pass
$ sudo openssl rsa -in /etc/ssl/keys/nginx.key.pass -out /etc/ssl/keys/nginx.key
+
+
+
Enter pass phrase for /etc/ssl/keys/nginx.key.org:
writing RSA key
- $
3. Nginx Configuration
diff --git a/tools/scripts/install-nginx.sh b/tools/scripts/install-nginx.sh
index 5553692..7fee79b 100644
--- a/tools/scripts/install-nginx.sh
+++ b/tools/scripts/install-nginx.sh
@@ -11,7 +11,10 @@ usermod -m -d /srv/www nginx
openssl genrsa -des3 -out /etc/ssl/keys/nginx.key 2048
openssl req -new -key /etc/ssl/keys/nginx.key -out /etc/ssl/certs/nginx.csr
-openssl x509 -req -days 365 -in /etc/ssl/certs/nginx.csr -signkey /etc/ssl/keys/nginx.key
+openssl x509 -req -days 365 \
+ -in /etc/ssl/certs/nginx.csr \
+ -signkey /etc/ssl/keys/nginx.key \
+ -out /etc/ssl/certs/nginx.crt
cp /etc/ssl/keys/nginx.key /etc/ssl/keys/nginx.key.pass
openssl rsa -in /etc/ssl/keys/nginx.key.pass -out /etc/ssl/keys/nginx.key
--
cgit