<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Nginx on nagg.eu</title><link>https://nagg.eu/tags/nginx/</link><description>Recent content in Nginx on nagg.eu</description><generator>Hugo</generator><language>en</language><lastBuildDate>Sat, 08 Jul 2023 00:00:00 +0000</lastBuildDate><atom:link href="https://nagg.eu/tags/nginx/index.xml" rel="self" type="application/rss+xml"/><item><title>We are in the cloud</title><link>https://nagg.eu/we-are-in-the-cloud/</link><pubDate>Sat, 08 Jul 2023 00:00:00 +0000</pubDate><guid>https://nagg.eu/we-are-in-the-cloud/</guid><description>&lt;p&gt;We are in the cloud, running on someone else&amp;rsquo;s computer.&lt;/p&gt;</description></item><item><title>Keepalived and libvirt MACVTAP network interfaces</title><link>https://nagg.eu/keepalived-and-libvirt-macvtap-network-interfaces/</link><pubDate>Wed, 13 Jan 2021 00:00:00 +0000</pubDate><guid>https://nagg.eu/keepalived-and-libvirt-macvtap-network-interfaces/</guid><description>&lt;p&gt;Keepalived is a routing software written in C that can be used to setup load
balancing and high availiability for Linux machines.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;NOTE: hypervisor is Debian 10 (Buster) with &lt;code&gt;libvirt&lt;/code&gt; and &lt;code&gt;qemu/kvm&lt;/code&gt;, virtual
machines also are Debian 10 (Buster).&lt;/em&gt;&lt;/p&gt;
&lt;h2 id="keepalived-configuration"&gt;Keepalived configuration&lt;/h2&gt;
&lt;p&gt;Install &lt;code&gt;keepalived&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;$ apt install keepalived
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Install &lt;code&gt;nginx&lt;/code&gt;, it will be use to check that keepalived is actually working:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;$ apt install nginx
$ systemctl enable --now nginx
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Configure &lt;code&gt;keepalived&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;$ vi /etc/keepalived/keepalived.conf
---
global_defs {
 enable_script_security # prevents tampering with the check script
 script_user root # defines which user runs the check script
}

vrrp_script chk_nginx {
 script &amp;#34;/opt/scripts/nginx-check.sh&amp;#34;
 interval 2 # run script every 2 seconds
 weight 2 # add 2 points if OK
}

vrrp_instance VI_1 {
 interface enp2s0 # interface to monitor
 virtual_router_id 51
 priority 101 # MASTER 101, BACKUP 100
 advert_int 1
 nopreempt # comment to not have the VIP go back to MASTER 
 # -&amp;gt; when it comes back online
 authentication {
 auth_type PASS
 auth_pass myPass # maximum 8 chars
 }
 virtual_ipaddress {
 10.10.0.12/24 # VIP (Virtual IP Address)
 }
 track_script {
 chk_nginx
 }
}
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Also add a script to check if &lt;code&gt;nginx&lt;/code&gt; is alive and well:&lt;/p&gt;</description></item><item><title>FreeBSD, Nginx and htpasswd file generation</title><link>https://nagg.eu/freebsd-nginx-and-htpasswd-file-generation/</link><pubDate>Sun, 01 Sep 2019 00:00:00 +0000</pubDate><guid>https://nagg.eu/freebsd-nginx-and-htpasswd-file-generation/</guid><description>&lt;p&gt;On most Linux distros it is possible to generate the htpasswd file entries simply
using the &lt;code&gt;htpasswd&lt;/code&gt; command line util.&lt;br&gt;
On FreeBSD the easiest way to accomplish the same task is using OpenSSL itself:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;
openssl passwd -apr1
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Enter the password twice to get a nice hash, copy that in the htpasswd file
with the usual &lt;code&gt;user:password_hash&lt;/code&gt; syntax.&lt;/p&gt;</description></item><item><title>FreeBSD, NGINX and TLSv1.3</title><link>https://nagg.eu/freebsd-nginx-and-tlsv1.3/</link><pubDate>Sat, 29 Jun 2019 00:00:00 +0000</pubDate><guid>https://nagg.eu/freebsd-nginx-and-tlsv1.3/</guid><description>&lt;p&gt;After a six months hiatus here is a new blogpost.&lt;br&gt;
This saturday I finally found the time to upgrade the configuration of the server
that hosts this very website.&lt;br&gt;
Software stack is pretty simple: &lt;code&gt;FreeBSD&lt;/code&gt; (version 12.0-p6),&lt;code&gt;nginx&lt;/code&gt; (version 1.15.10)
and &lt;code&gt;OpenSSL&lt;/code&gt; (version 1.1.1a-freebsd).&lt;/p&gt;
&lt;p&gt;Install the required software:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;
$ pkg install nginx-devel py36-certbot
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Get a SSL certificate from &lt;a href="https://letsencrypt.org/"&gt;letsencrypt&lt;/a&gt;:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;
$ certbot-3.6 certonly --standalone -d domain.tld -d www.domain.tld
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Certfiles location is &lt;code&gt;/usr/local/etc/letsencrypt/live/&amp;lt;domain.tld&amp;gt;&lt;/code&gt;, you might,
or might not, want to move them to another directory.&lt;/p&gt;</description></item><item><title>Nginx and XMPP over TLS</title><link>https://nagg.eu/nginx-and-xmpp-over-tls/</link><pubDate>Sun, 28 Oct 2018 00:00:00 +0000</pubDate><guid>https://nagg.eu/nginx-and-xmpp-over-tls/</guid><description>&lt;p&gt;XMPP over TLS (formerly XEP-0368) is a clever mechanism that allows users to
connect to a XMPP server from networks that restrict outgoing traffic only to
specific ports; this block is circumvent by routing XMPP traffic via port TCP
443.&lt;br&gt;
If the server hosts only a XMPP server setting up XMPP over TLS is pretty easy,
just instruct the server to listen on port 443.&lt;br&gt;
If the server also runs a webserver which is listening on port 443 things are a
bit more complicated; luckily Nginx provides a way to manage XMPP traffic and
redirect it to the XMPP server.&lt;/p&gt;</description></item><item><title>Nginx, PHP-FPM, SELinux and sendmail</title><link>https://nagg.eu/nginx-php-fpm-selinux-and-sendmail/</link><pubDate>Fri, 23 Mar 2018 13:54:15 +0000</pubDate><guid>https://nagg.eu/nginx-php-fpm-selinux-and-sendmail/</guid><description>&lt;p&gt;Since I am a real master at forgiving things I am writing this one down.&lt;br&gt;
PHP mail function relies on sendmail but SELinux by default block webservers from sending emails, the usual error that pop-out is:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;cat /var/log/maillog&amp;#34;&amp;gt;
---
sendmail[16328]: NOQUEUE: SYSERR(nginx): /etc/mail/sendmail.cf: line 0: cannot open: Permission denied
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Allow webservers to send email is as easy as editing the appropriate SELinux boolean:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;setsebool -P httpd_can_sendmail 1
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Use &lt;code&gt;sestatus&lt;/code&gt; to check SELinux booleans:&lt;/p&gt;</description></item><item><title>Nginx, PHP-FPM caching done right</title><link>https://nagg.eu/nginx-php-fpm-caching-done-right/</link><pubDate>Wed, 22 Apr 2015 23:38:54 +0000</pubDate><guid>https://nagg.eu/nginx-php-fpm-caching-done-right/</guid><description>&lt;p&gt;The whole web is full of pseudo guides on how to properly - that is the key
word here - configure Nginx to perform caching alongside with PHP-FPM, but
every single one of them fails to mention some minor steps resulting in a
borked half functioning implementation.&lt;br&gt;
For example, not a single one mention the necessity to edit &lt;code&gt;/etc/php.ini&lt;/code&gt; and
set &lt;code&gt;session.use_cookies&lt;/code&gt; to &lt;code&gt;0&lt;/code&gt;.&lt;br&gt;
Too bad that without doing so caching with WordPress in combination with
certain plugins or themes (for example MainWP or Enfold theme) is completely
not working; the following headers get added to every HTTP response:&lt;/p&gt;</description></item><item><title>Get rid of SHA-1 – nginx, TLSv1.2, PFS and SHA-2</title><link>https://nagg.eu/get-rid-of-sha-1-nginx-tlsv1-2-pfs-and-sha-2/</link><pubDate>Tue, 09 Sep 2014 18:02:32 +0000</pubDate><guid>https://nagg.eu/get-rid-of-sha-1-nginx-tlsv1-2-pfs-and-sha-2/</guid><description>&lt;p&gt;Everyone who knows me a little bit knows how much I dislike Google but this time we really should thank them for taking a real step toward a more secure web.&lt;br&gt;
They are finally moving away from SHA-1 to the much more secure SHA-2, more info can be found here: &lt;!-- raw HTML omitted --&gt;&lt;a href="http://googleonlinesecurity.blogspot.it/2014/09/gradually-sunsetting-sha-1.html"&gt;http://googleonlinesecurity.blogspot.it/2014/09/gradually-sunsetting-sha-1.html&lt;/a&gt;&lt;!-- raw HTML omitted --&gt;&lt;/p&gt;
&lt;h3 id="-setup"&gt;.:. Setup&lt;/h3&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;CentOS 6.5 x86_64
nginx/1.6.1
OpenSSL 1.0.1e-fips 11 Feb 2013
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Nginx developers provide an up to date repository (&lt;!-- raw HTML omitted --&gt;&lt;a href="http://wiki.nginx.org/Install"&gt;http://wiki.nginx.org/Install&lt;/a&gt;&lt;!-- raw HTML omitted --&gt;)for CentOS:&lt;/p&gt;</description></item><item><title>nginx and TLS v1.2</title><link>https://nagg.eu/nginx-and-tls-v1-2/</link><pubDate>Sat, 10 Aug 2013 14:03:39 +0000</pubDate><guid>https://nagg.eu/nginx-and-tls-v1-2/</guid><description>&lt;p&gt;Given that SSL and TLS, especially v1.0, suffer from serious security issues (e.g. &lt;!-- raw HTML omitted --&gt;&lt;a href="https://en.wikipedia.org/wiki/Transport_Layer_Security#TLS"&gt;https://en.wikipedia.org/wiki/Transport_Layer_Security#TLS&lt;/a&gt;&lt;!-- raw HTML omitted --&gt;) I thought it would be a good idea to use the latest and more secure version of it: v1.2.&lt;br&gt;
On CentOS 6.4 the openssl version included is quite old and doesn&amp;rsquo;t support TLS v1.1 and 1.2.&lt;br&gt;
So, first of all we have to install the latest version 1.0.1e, it can be done compiling from sources or by adding a third party repository; I chose the latter.&lt;/p&gt;</description></item><item><title>WordPress admin, SSL, Apache + nginx</title><link>https://nagg.eu/wordpress-admin-ssl-apache-nginx/</link><pubDate>Tue, 30 Jul 2013 15:49:37 +0000</pubDate><guid>https://nagg.eu/wordpress-admin-ssl-apache-nginx/</guid><description>&lt;p&gt;Let&amp;rsquo;s say we have a WordPress blog and we would like to encrypt our login pages and the whole back-end of the site.&lt;br&gt;
There are many ways to do it, but since I already have a nginx instance configured as reverse proxy running in front of Apache I&amp;rsquo;ll use it to &lt;code&gt;protect&lt;/code&gt; my admin pages and logins.&lt;br&gt;
In this page I&amp;rsquo;ll not cover Apache&amp;rsquo;s configuration, which, by the way, is trivial to say the least, so please refer to this other post: &lt;!-- raw HTML omitted --&gt;Apache + nginx as reverse proxy&lt;!-- raw HTML omitted --&gt;.&lt;br&gt;
Using the configuration posted in the above&amp;rsquo;s link as starting point, to add SSL encryption to admin pages we should add a couple more bunch of lines of code.&lt;br&gt;
First of all, we must create our own Certificate Authority and issue a SSL certificate.&lt;br&gt;
Another option is buying a certificate, but I don&amp;rsquo;t trust CA (certificate forgery anyone?) and I don&amp;rsquo;t mind having a properly signed certificate for a page I am the only one accessing to.&lt;br&gt;
Follows a brief explanation on how to create a CA and issue a certificate.&lt;/p&gt;</description></item><item><title>Apache + nginx as reverse proxy</title><link>https://nagg.eu/apache-nginx-as-reverse-proxy/</link><pubDate>Fri, 21 Jun 2013 16:11:13 +0000</pubDate><guid>https://nagg.eu/apache-nginx-as-reverse-proxy/</guid><description>&lt;p&gt;One of the things I was planning to do but never did is installing nginx as &lt;!-- raw HTML omitted --&gt;reverse proxy&lt;!-- raw HTML omitted --&gt; in front of Apache.&lt;br&gt;
nginx is present in the epel repos for CentOS, so the installation process is just a matter of:&lt;!-- raw HTML omitted --&gt;&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;yum install nginx mysql mysql-server phpmyadmin httpd
&lt;/code&gt;&lt;/pre&gt;&lt;!-- raw HTML omitted --&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;wget -q -O - http://www.atomicorp.com/installers/atomic | sh
&lt;/code&gt;&lt;/pre&gt;&lt;!-- raw HTML omitted --&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;yum install mod_rpaf
&lt;/code&gt;&lt;/pre&gt;&lt;!-- raw HTML omitted --&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;mkdir /etc/nginx/v.hosts
&lt;/code&gt;&lt;/pre&gt;&lt;!-- raw HTML omitted --&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;vi /etc/nginx/nginx.con
&lt;/code&gt;&lt;/pre&gt;&lt;!-- raw HTML omitted --&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;http {
 include v.hosts/*.conf;
 include /etc/nginx/mime.types;
 default_type application/octet-stream;
 
 log_format main &amp;#39;$remote_addr - $remote_user [$time_local] &amp;#34;$request&amp;#34; &amp;#39;
 &amp;#39;$status $body_bytes_sent &amp;#34;$http_referer&amp;#34; &amp;#39;
 &amp;#39;&amp;#34;$http_user_agent&amp;#34; &amp;#34;$http_x_forwarded_for&amp;#34;&amp;#39;;
 
 access_log /var/log/nginx/access.log main; 
 
 charset utf-8;
 keepalive_timeout 65;
 server_tokens off;
 sendfile on;
 tcp_nopush on;
 tcp_nodelay off;
 
# Default Server Block to catch undefined host names
# server {
# listen 80;
# server_name _; 
# root /usr/share/nginx/html;
# index index.html index.htm; }
}
&lt;/code&gt;&lt;/pre&gt;&lt;!-- raw HTML omitted --&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;/usr/sbin/nginx -t
&lt;/code&gt;&lt;/pre&gt;&lt;!-- raw HTML omitted --&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt; server {
 listen 80;
	 server_name nagg.eu;
 
 access_log off;
 error_log off;
 
 location / {
 proxy_pass http://127.0.0.1:8080;
 proxy_set_header X-Real-IP $remote_addr;
 proxy_set_header Host $host;
 proxy_redirect off;
 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 proxy_connect_timeout 90;
 proxy_send_timeout 90;
 proxy_read_timeout 90;
 client_max_body_size 10m;
 client_body_buffer_size 128k;
 proxy_buffer_size 4k;
 proxy_buffers 4 32k;
 proxy_busy_buffers_size 64k;
 }
 }
&lt;/code&gt;&lt;/pre&gt;&lt;!-- raw HTML omitted --&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;sudo /usr/sbin/nginx -t
service nginx restart
&lt;/code&gt;&lt;/pre&gt;&lt;!-- raw HTML omitted --&gt;
&lt;!-- raw HTML omitted --&gt;</description></item></channel></rss>