{"id":494,"date":"2024-06-15T16:13:53","date_gmt":"2024-06-15T16:13:53","guid":{"rendered":"https:\/\/xircx.com\/?p=494"},"modified":"2024-06-15T16:14:47","modified_gmt":"2024-06-15T16:14:47","slug":"wordpress-nginx","status":"publish","type":"post","link":"https:\/\/xircx.com\/?p=494","title":{"rendered":"WordPress + Nginx"},"content":{"rendered":"\n<p>I made a resend swap from Apache2 to Nginx for speed improvements. <\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>This guild is for for Ubuntu 22.04 and assuming you are already running a WordPress site. <\/p>\n\n\n\n<p>Your will need to install 4 packages <\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Certbox LetsEncrypt<\/li>\n\n\n\n<li>python3-certbot-apache<\/li>\n\n\n\n<li>Nginx<\/li>\n\n\n\n<li>Php8.1 or what ever version you require for your site. (Optional)<\/li>\n<\/ol>\n\n\n\n<p><\/p>\n\n\n\n<p class=\"has-kenta-font-medium-font-size\"><strong>Part 1 <\/strong><\/p>\n\n\n\n<p>Install everything you need<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install certbot python3-certbot-apache php8.1 nginx<\/code><\/pre>\n\n\n\n<p>now to make the packages work&#8230; <\/p>\n\n\n\n<p>PHP setup is optional if you already have a working site.<\/p>\n\n\n\n<p>Lets start with php8.1<\/p>\n\n\n\n<p>You will need to enable it and build the scripts for it<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>update-alternatives --set php \/usr\/bin\/php8.1\nupdate-alternatives --config php\nphp -v<\/code><\/pre>\n\n\n\n<p class=\"has-kenta-font-medium-font-size\"><strong>Part 2<\/strong><\/p>\n\n\n\n<p>Now lets make the necessary firewall rules to permit ports 80\/443<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo ufw app list\nsudo ufw allow 'Nginx HTTP'\nsudo ufw allow 'Nginx HTTPS'<\/code><\/pre>\n\n\n\n<p class=\"has-kenta-font-medium-font-size\"><strong>Part 4<\/strong><\/p>\n\n\n\n<p>Generate your LetsEncrypt certs<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>certbot certonly --manual --preferred-challenge dns -d \"&lt;Your Domain>\" -d \"*.&lt;Your Domain>\"<\/code><\/pre>\n\n\n\n<p> This will create a basic config for you under \/etc\/nginx\/sites-available\/ and store your new certs in \/etc\/letsencrypt\/live\/&lt;Your Domain>\/<\/p>\n\n\n\n<p>Now to configure Nginx<\/p>\n\n\n\n<p>Nginx has a few components that need to be setup for before its operational <\/p>\n\n\n\n<p>Modify the Certbot generated config file for your domain<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cd \/etc\/nginx\/sites-available\/<br>vim &lt;your domain><br><br><\/code><\/pre>\n\n\n\n<p>Replace your domain config code with the following code<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>server {\n    listen 443 ssl http2;\n    listen &#91;::]:443 ssl http2;\n        server_name &lt;Your Domain>;\n\n        ssl_certificate \/etc\/letsencrypt\/live\/&lt;Your Domain>\/fullchain.pem;\n        ssl_certificate_key \/etc\/letsencrypt\/live\/&lt;Your Domain>\/privkey.pem;\n\n        access_log \/var\/log\/access.log;\n        error_log \/var\/log\/error.log;\n\n        root \/var\/www\/&lt;Your Domain>;\n        index index.php;\n\n    location \/ {\n        try_files $uri $uri\/ \/index.php?$args;\n    }\n\n    location ~ \\.php$ {\n        try_files $uri =404;\n        fastcgi_split_path_info ^(.+\\.php)(\/.+)$;\n        fastcgi_pass unix:\/run\/php\/php8.1-fpm.sock;\n        fastcgi_index index.php;\n        include fastcgi.conf;\n    }\n}\n\nserver {\n    listen 443 ssl http2;\n    listen &#91;::]:443 ssl http2;\n\n        server_name www.&lt;Your Domain>;\n\n        ssl_certificate \/etc\/letsencrypt\/live\/&lt;Your Domain>\/fullchain.pem;\n        ssl_certificate_key \/etc\/letsencrypt\/live\/&lt;Your Domain>\/privkey.pem;\n\n    return 301 https:\/\/&lt;Your Domain>$request_uri;\n}\n\nserver {\n    listen 80;\n    listen &#91;::]:80;\n\n        server_name &lt;Your Domain> www.&lt;Your Domain>;\n\n        return 301 https:\/\/&lt;Your Domain>$request_uri;\n}<\/code><\/pre>\n\n\n\n<p>The above config will load the site on port 80 and redirect it to port 443 while also accepting connections on 443 its self. Apply your. You will be able to create a custom path for your access and error log files.<\/p>\n\n\n\n<p>Start the Nginx service. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>systemctl start nginx<\/code><\/pre>\n\n\n\n<p>Once Nginx has started try to load your website again via DNS name on http and https to verity the redirect is working. Something to keep in mind is that Nginx does take a few sec to begin serving web content.<\/p>\n\n\n\n<p>You may want to setup a systemd service or crontab job to automatically renew your cert with Certbot<\/p>\n\n\n\n<p><\/p>\n<div class=\"pvc_clear\"><\/div><p id=\"pvc_stats_494\" class=\"pvc_stats all  \" data-element-id=\"494\" style=\"\"><i class=\"pvc-stats-icon small\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/xircx.com\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p><div class=\"pvc_clear\"><\/div>","protected":false},"excerpt":{"rendered":"<p>I made a resend swap from Apache2 to Nginx for speed improvements. This guild is for for Ubuntu 22.04 and assuming you are already running a WordPress site. Your will need to install 4 packages Part 1 Install everything you need now to make the packages work&#8230; PHP setup is optional if you already have [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":495,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"site-container-style":"default","site-container-layout":"default","site-sidebar-layout":"default","site-transparent-header":"default","disable-article-header":"default","disable-site-header":"default","disable-site-footer":"default","disable-content-area-spacing":"default","advanced_seo_description":"configure nginx on ubuntu 22.04 and host a secure https wordpress site","jetpack_seo_html_title":"Nginx on Ubuntu 22.04","jetpack_seo_noindex":false,"pgc_sgb_lightbox_settings":"","_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[9],"tags":[],"class_list":["post-494","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog"],"jetpack_featured_media_url":"https:\/\/xircx.com\/wp-content\/uploads\/2024\/06\/ai_image7-jpeg.webp","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/xircx.com\/index.php?rest_route=\/wp\/v2\/posts\/494","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/xircx.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xircx.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xircx.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/xircx.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=494"}],"version-history":[{"count":1,"href":"https:\/\/xircx.com\/index.php?rest_route=\/wp\/v2\/posts\/494\/revisions"}],"predecessor-version":[{"id":496,"href":"https:\/\/xircx.com\/index.php?rest_route=\/wp\/v2\/posts\/494\/revisions\/496"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/xircx.com\/index.php?rest_route=\/wp\/v2\/media\/495"}],"wp:attachment":[{"href":"https:\/\/xircx.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=494"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xircx.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=494"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xircx.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=494"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}