{"id":141,"date":"2019-11-21T09:55:45","date_gmt":"2019-11-21T08:55:45","guid":{"rendered":"http:\/\/blog.remyblom.nl\/?p=141"},"modified":"2021-05-26T09:40:15","modified_gmt":"2021-05-26T07:40:15","slug":"openbsd-6-6-switching-from-httpd-to-nginx","status":"publish","type":"post","link":"https:\/\/blog.remyblom.nl\/?p=141","title":{"rendered":"OpenBSD 6.6: switching back from httpd to nginx"},"content":{"rendered":"\n<p>I really like the idea of httpd being secure and lightweight and all, but I also need flexibily, especially from my webserver.  Couple of things I was missing in httpd are:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>configuring multiple files as index: <code>index \"index.html index.php index.htm\"<\/code><\/li><li>block access to certain locations based on IP<\/li><li>using custom error pages<\/li><li>dynamic vhosts (although I still have to figure out how to do those with https)<\/li><\/ul>\n\n\n\n<p>I read man pages, asked questions online, used google (as it turns out <strong>openbsd httpd<\/strong> is a really shitty search-query when you don&#8217;t just want to install wordpress&#8230;.). I even looked at the code, but my C knowledge is rusty, I know where to make the needed changes in the code, but don&#8217;t know quite how to do it. And while I love to learn, that will take some time and quite frankly I don&#8217;t have that right now, so&#8230;. Let&#8217;s go back to nginx!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">OEMP!<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>$ doas pkg_add nginx\n$ doas mkdir \/etc\/nginx\/sites-available\n$ doas mkdir \/etc\/nginx\/sites-enabled<\/code><\/pre>\n\n\n\n<p>For now I just wanted my sites back online; I tweaked <code>\/etc\/nginx\/nginx.conf<\/code> so it uses <code>sites-available<\/code> and <code>sites-enabled<\/code> directories:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \/etc\/nginx\/nginx.conf:\nworker_processes  1;\n\nworker_rlimit_nofile 1024;\nevents {\n    worker_connections  800;\n}\n\nhttp {\n    include       mime.types;\n    default_type  application\/octet-stream;\n    index         index.html index.php index.htm;\n\n    keepalive_timeout  65;\n    server_tokens off;\n    disable_symlinks off;\n\n    include sites-enabled\/*;\n}<\/code><\/pre>\n\n\n\n<p>Simple and effective main <code>nginx.conf<\/code> that came with the install with all outcommented lines deleted. After that I created <code>\/etc\/nginx\/php-fpm.conf<\/code> that can be included in every site-config that needs it:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \/etc\/nginx\/php-fpm.conf\n# pass the PHP scripts to FastCGI server listening on unix socket\n#\nlocation ~ \\.php$ {\n   try_files      $uri $uri\/ =404;\n   fastcgi_pass   unix:run\/php-fpm.sock;\n   fastcgi_index  index.php;\n   fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;\n   include        fastcgi_params;\n}<\/code><\/pre>\n\n\n\n<p>So now for a simple site that allows for dynamic vhosting using only http:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \/etc\/nginx\/sites-available\/dynamic.vhosts\nserver {\n\tlisten 80 default_server;\n\tlisten [::]:80 default_server;\n\n\tindex index.php index.html index.htm index.nginx-debian.html;\n\n\tset $basepath \"\/vhosts\";\n\tset $domain $host;\n\n\tif ($domain ~ \"^(.[^.]*)\\.(.[^.]*)$\") {\n\t\tset $rootpath \"$1.$2\/www\/\";\n\t\tset $servername $domain;\n\t}\n\n\tif ($domain ~ \"^(.[^.]*)\\.(.[^.]*)\\.(.[^.]*)$\") {\n\t        set $rootpath \"$2.$3\/$1\/\";\n                set $servername $domain;\n\t}\n\n\tserver_name $servername;\n\troot $basepath\/$rootpath;\n\n\tlocation \/ {\n\t\t# First attempt to serve request as file, then\n\t\t# as directory, then fall back to displaying a 404.\n\t\ttry_files $uri $uri\/ =404;\n\t}\n\n\tinclude php-fpm.conf;\n}<\/code><\/pre>\n\n\n\n<p>Enable this site:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ doas ln -sf \/etc\/nginx\/sites-available\/dynamic.vhosts \/etc\/nginx\/sites-enabled\/dynamic.vhosts<\/code><\/pre>\n\n\n\n<p>With all the configfiles in place it is time to switch:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ doas rcctl stop httpd\n$ doas rcctl disable httpd\n$ doas rcctl enable nginx\n$ doas rcctl start nginx<\/code><\/pre>\n\n\n\n<p>Of course this is not yet final, I&#8217;ll have to <a href=\"https:\/\/blog.remyblom.nl\/?p=144\">setup nginx to respond to the acme-challenges that I have in my cron, I still have to setup https<\/a> too, but at least my sites are back online no matter whether they have an <strong>index.html<\/strong> or an <strong>index.php<\/strong>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I really like the idea of httpd being secure and lightweight and all, but I also need flexibily, especially from my webserver. Couple of things I was missing in httpd are: configuring multiple files as index: index &#8220;index.html index.php index.htm&#8221; block access to certain locations based on IP using custom error pages dynamic vhosts (although &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/blog.remyblom.nl\/?p=141\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;OpenBSD 6.6: switching back from httpd to nginx&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10,4,2],"tags":[],"class_list":["post-141","post","type-post","status-publish","format-standard","hentry","category-lemp","category-openbsd","category-vps"],"_links":{"self":[{"href":"https:\/\/blog.remyblom.nl\/index.php?rest_route=\/wp\/v2\/posts\/141","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.remyblom.nl\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.remyblom.nl\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.remyblom.nl\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.remyblom.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=141"}],"version-history":[{"count":7,"href":"https:\/\/blog.remyblom.nl\/index.php?rest_route=\/wp\/v2\/posts\/141\/revisions"}],"predecessor-version":[{"id":276,"href":"https:\/\/blog.remyblom.nl\/index.php?rest_route=\/wp\/v2\/posts\/141\/revisions\/276"}],"wp:attachment":[{"href":"https:\/\/blog.remyblom.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=141"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.remyblom.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=141"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.remyblom.nl\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=141"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}