{"id":11608,"date":"2022-06-08T08:14:00","date_gmt":"2022-06-08T06:14:00","guid":{"rendered":"https:\/\/raspberrytips.com\/?p=11608"},"modified":"2026-07-15T01:10:06","modified_gmt":"2026-07-14T23:10:06","slug":"nginx-on-raspberry-pi","status":"publish","type":"post","link":"https:\/\/raspberrytips.com\/nginx-on-raspberry-pi\/","title":{"rendered":"Getting Started With Nginx on Raspberry Pi (Full Guide)"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Nginx is primarily a web server, but can also be used as a proxy server. It&#8217;s free, open-source and often in direct competition with Apache to build web applications. As a web developer, I&#8217;m more used to Apache, but Nginx is known to be almost 3 times faster and lighter, which is great for a Raspberry Pi. Let&#8217;s see how to get it on your Pi.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>The main package for Nginx is available in the default Raspberry Pi repository, so it can be installed with apt directly: <em>sudo apt install nginx<\/em>. The web files can then be created under <em>\/var\/www\/html<\/em> and the configuration can be modified in the <em>\/etc\/nginx<\/em> folder.<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Don&#8217;t worry, I&#8217;ll explain everything in detail if you need a more step-by-step approach to this. Let&#8217;s start with an introduction, to make sure you understand what is Nginx and when to use it.<\/p>\n\n\n<style>.kb-table-of-content-nav.kb-table-of-content-id19563_c031ec-35 .kb-table-of-content-wrap{padding-top:var(--global-kb-spacing-sm, 1.5rem);padding-right:var(--global-kb-spacing-sm, 1.5rem);padding-bottom:var(--global-kb-spacing-sm, 1.5rem);padding-left:var(--global-kb-spacing-sm, 1.5rem);background-color:var(--global-palette7, #EDF2F7);box-shadow:0px 0px 14px 0px rgba(0, 0, 0, 0.2);}.kb-table-of-content-nav.kb-table-of-content-id19563_c031ec-35 .kb-table-of-contents-title-wrap{padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px;}.kb-table-of-content-nav.kb-table-of-content-id19563_c031ec-35 .kb-table-of-contents-title{font-weight:regular;font-style:normal;}.kb-table-of-content-nav.kb-table-of-content-id19563_c031ec-35 .kb-table-of-content-wrap .kb-table-of-content-list{font-size:var(--global-kb-font-size-sm, 0.9rem);font-weight:regular;font-style:normal;margin-top:var(--global-kb-spacing-sm, 1.5rem);margin-right:0px;margin-bottom:0px;margin-left:0px;}.kb-table-of-content-nav.kb-table-of-content-id19563_c031ec-35 .kb-toggle-icon-style-basiccircle .kb-table-of-contents-icon-trigger:after, .kb-table-of-content-nav.kb-table-of-content-id19563_c031ec-35 .kb-toggle-icon-style-basiccircle .kb-table-of-contents-icon-trigger:before, .kb-table-of-content-nav.kb-table-of-content-id19563_c031ec-35 .kb-toggle-icon-style-arrowcircle .kb-table-of-contents-icon-trigger:after, .kb-table-of-content-nav.kb-table-of-content-id19563_c031ec-35 .kb-toggle-icon-style-arrowcircle .kb-table-of-contents-icon-trigger:before, .kb-table-of-content-nav.kb-table-of-content-id19563_c031ec-35 .kb-toggle-icon-style-xclosecircle .kb-table-of-contents-icon-trigger:after, .kb-table-of-content-nav.kb-table-of-content-id19563_c031ec-35 .kb-toggle-icon-style-xclosecircle .kb-table-of-contents-icon-trigger:before{background-color:var(--global-palette7, #EDF2F7);}<\/style>\n\n<p class='ml_begpost' id='ml_begpost_commands'>If you&#8217;re new to Raspberry Pi or Linux, I\u2019ve got something that can help you right away! <br \/><a rel='noopener' href='https:\/\/raspberrytips.com\/downloads\/?source=begpost&#038;lm=4' target='_blank'>Download my free Linux commands cheat sheet<\/a> \u2013 it\u2019s a quick reference guide with all the essential commands you\u2019ll need to get things done on your Raspberry Pi. <a rel='noopener' href='https:\/\/raspberrytips.com\/downloads\/?source=begpost&#038;lm=4' target='_blank'><b>Click here to get it for free!<\/b><\/a><\/p>\n\n\n<h2 class=\"wp-block-heading\">What is Nginx and What&#8217;s It Used For? <\/h2>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">nginx [engine x] is an HTTP and reverse proxy server, a mail proxy server, and a generic TCP\/UDP proxy server, originally written by Igor Sysoev.<\/p>\n<cite><a href=\"https:\/\/nginx.org\/en\/\" target=\"_blank\" rel=\"noopener\" data-lasso-id=\"3389\">Nginx website<\/a><\/cite><\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">As we are Raspberry Pi users, we&#8217;ll generally use Nginx in two cases: for a web server or a web proxy. Let&#8217;s take a few seconds to explain both usages.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Web Server<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/raspberrytips.com\/host-website-raspberry-pi\/\" data-type=\"link\" data-id=\"https:\/\/raspberrytips.com\/host-website-raspberry-pi\/\">A web server<\/a> is simply an app installed on a server, to answer HTTP (or HTTPS) requests. If you type the Raspberry Pi IP address in a web browser directly after the system installation, you&#8217;ll get an error. Nginx is the piece of software you need to make your Pi answer this request.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you already used Apache or even a Python web server, it&#8217;s the same idea. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Nginx is known to use less memory and resources while performing 2.5 times faster than Apache overall. Nginx can also handle a high volume of connections.<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This make it the perfect choice for high traffic websites (Netflix is using it for example), or low-resource servers <a href=\"https:\/\/raspberrytips.com\/pi-projects-to-save-money\/\">used to save money<\/a> on hosting costs (like a Raspberry Pi!).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Helping you to install it on your Raspberry Pi is my main goal today, we&#8217;ll get to it in the next part. But first, let&#8217;s talk a bit about the web proxy usage.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Web Proxy<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>A web proxy also answer web requests, but it generally acts as a gateway between the user on the Internet and another app.<\/strong> For example, Nginx can answer requests on port 80 and redirect it to your Plex server, <a rel=\"noopener\" href=\"https:\/\/raspberrytips.com\/torrent-box-raspberry-pi\/\" data-type=\"post\" data-id=\"11145\" target=\"_blank\" data-lasso-id=\"3390\">Torrent web interface<\/a> or <a rel=\"noopener\" href=\"https:\/\/raspberrytips.com\/install-webmin-raspberry-pi\/\" data-type=\"post\" data-id=\"2747\" target=\"_blank\" data-lasso-id=\"3391\">Webmin<\/a>. These apps that are listening on a different port by default.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">At work, we had a Rocket Chat server listening on a random port (3000, if I recall correctly). But when we type the IP address without the port, Nginx would answer the request and display the Rocket Chat page automatically. This is great to share an easy URL with other users.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Obviously, a web proxy is not only used for convenience, but also for increased security, better performances, logging purposes or even load balancing (you can distribute the requests to multiple servers).<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Getting Started with Nginx on Raspberry Pi<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In this section, I&#8217;ll show you how to install Nginx on your Raspberry Pi, and run it as a basic web server.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Can a Raspberry Pi Run Nginx?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Nginx can be installed on Raspberry Pi with APT. The Nginx package available in the default repository and is well-supported on Raspberry Pi. <\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">By the way, it&#8217;s a good idea to use it as a web server on Raspberry Pi, as it&#8217;s generally lighter and faster than other alternatives (<a data-lasso-id=\"3392\" href=\"https:\/\/raspberrytips.com\/web-server-setup-on-raspberry-pi\/\" data-type=\"post\" data-id=\"1017\" target=\"_blank\" rel=\"noopener\">like Apache<\/a>).<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">How to Install Nginx on a Raspberry Pi<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Installing Nginx on a Raspberry Pi is straightforward:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Open a terminal. <\/strong><\/li>\n\n\n\n<li><strong>Refresh your package list to get the latest versions:<\/strong><br><code>sudo apt update<\/code><\/li>\n\n\n\n<li><strong>Install Nginx:<br><\/strong><code>sudo apt install nginx<\/code><\/li>\n<\/ul>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"581\" height=\"138\" src=\"https:\/\/raspberrytips.com\/wp-content\/uploads\/2022\/06\/install_nginx.jpg\" alt=\"\" class=\"wp-image-47353\" srcset=\"https:\/\/raspberrytips.com\/wp-content\/uploads\/2022\/06\/install_nginx.jpg 581w, https:\/\/raspberrytips.com\/wp-content\/uploads\/2022\/06\/install_nginx-300x71.jpg 300w\" sizes=\"auto, (max-width: 581px) 100vw, 581px\" \/><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">A few seconds later, Nginx is installed on your device, and you can already start using it.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">First Steps with Nginx on Raspberry Pi<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">To check if everything was installed correctly, start by visiting http:\/\/IP, replacing &#8220;IP&#8221; with your Raspberry Pi IP address. (You can check out my article on <a data-lasso-id=\"3393\" href=\"https:\/\/raspberrytips.com\/find-current-ip-raspberry-pi\/\" data-type=\"post\" data-id=\"96\" target=\"_blank\" rel=\"noopener\">how to find your Raspberry Pi IP address<\/a> if you don&#8217;t know it.)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In your web browser, it should load something like this:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"652\" height=\"231\" src=\"https:\/\/raspberrytips.com\/wp-content\/uploads\/2022\/06\/nginx-default-page.jpg\" alt=\"\" class=\"wp-image-11614\" srcset=\"https:\/\/raspberrytips.com\/wp-content\/uploads\/2022\/06\/nginx-default-page.jpg 652w, https:\/\/raspberrytips.com\/wp-content\/uploads\/2022\/06\/nginx-default-page-300x106.jpg 300w\" sizes=\"auto, (max-width: 652px) 100vw, 652px\" \/><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">It means Nginx is installed, and the web service has started properly. <br>The default page can be found at <em>\/var\/www\/html\/index.nginx-debian.html<\/em> on your system.<br>You can edit it, or remove it and start over from scratch.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Your web files need to be saved under <em>\/var\/www\/html<\/em> to be accessible from a web browser. Use <em>index.html<\/em> as the main page to be shown when accessing http:\/\/IP.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>If you need to change anything in the default Nginx configuration, you can edit the main configuration file with:<\/strong><br><code>sudo nano \/etc\/nginx\/nginx.conf<\/code><\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"501\" src=\"https:\/\/raspberrytips.com\/wp-content\/uploads\/2022\/06\/nginx_default_conf-1024x501.jpg\" alt=\"\" class=\"wp-image-47354\" srcset=\"https:\/\/raspberrytips.com\/wp-content\/uploads\/2022\/06\/nginx_default_conf-1024x501.jpg 1024w, https:\/\/raspberrytips.com\/wp-content\/uploads\/2022\/06\/nginx_default_conf-300x147.jpg 300w, https:\/\/raspberrytips.com\/wp-content\/uploads\/2022\/06\/nginx_default_conf-768x376.jpg 768w, https:\/\/raspberrytips.com\/wp-content\/uploads\/2022\/06\/nginx_default_conf.jpg 1118w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">And as with Apache, there are two subfolders there to tweak the configuration for each website or app hosted on your Raspberry Pi:<br><code>\/etc\/nginx\/sites-enabled\/<br>\/etc\/nginx\/sites-available\/<\/code><br>We&#8217;ll get back to this later to allow PHP code in our web files.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can find the <a rel=\"noopener\" href=\"http:\/\/nginx.org\/en\/docs\/\" target=\"_blank\" data-lasso-id=\"3394\">official documentation<\/a> on their website if you need further explanation.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Upgrade Nginx to Support PHP and MySQL<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">For some basic projects, maybe HTML files are enough. But in most cases, you will need to use PHP code and a MySQL database. This is not straightforward when you are doing this for the first time, so I&#8217;ll guide you with this too. It will also help to better understand the Nginx configuration.<\/p>\n\n\n\n<p class=\"has-background wp-block-paragraph\" style=\"background-color:#fadce4\"><strong>Note<\/strong>: I have a video lesson available for the community members, where I explain everything to host a website at home. It&#8217;s built with Apache instead of Nginx, but most of the steps are the same. <a rel=\"noreferrer noopener\" href=\"https:\/\/raspberrytips.com\/school\/community\/?coupon=IP25CTY&amp;utm_source=raspberrytips&amp;utm_medium=website&amp;utm_campaign=inpost\" target=\"_blank\">You can join here and watch it directly<\/a> if you are interested (with 10+ other lessons for Raspberry Pi and many other benefits).<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">PHP Installation<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>PHP is used to add dynamic content into your web pages<\/strong>. For example, this website use the same HTML template for all blog posts, and the blog post content is dynamic, using PHP to display the tutorial you are looking for (depending on the URL).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here&#8217;s how to enable PHP on your Nginx server:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>First, you need to <strong>install PHP on your system<\/strong>:<br><code>sudo apt install php-fpm<br><\/code>PHP-FPM is a better choice than the usual PHP mod for performances. And it works particularly well with Nginx.<\/li>\n\n\n\n<li>Then you have to <strong>tell Nginx to accept PHP code and extension<\/strong> (index.php for example).\n<ul class=\"wp-block-list\">\n<li><strong>Edit the default configuration file<\/strong>:<br><code>sudo nano \/etc\/nginx\/sites-enabled\/default<\/code><\/li>\n\n\n\n<li><strong>Add index.php to the list of index files:<br><\/strong><code>index index.php index.html index.htm index.nginx-debian.html;<br><\/code><img loading=\"lazy\" decoding=\"async\" width=\"1132\" height=\"83\" class=\"wp-image-11617\" style=\"\" src=\"https:\/\/raspberrytips.com\/wp-content\/uploads\/2022\/06\/index-files-nginx.jpg\" alt=\"\" srcset=\"https:\/\/raspberrytips.com\/wp-content\/uploads\/2022\/06\/index-files-nginx.jpg 1132w, https:\/\/raspberrytips.com\/wp-content\/uploads\/2022\/06\/index-files-nginx-300x22.jpg 300w, https:\/\/raspberrytips.com\/wp-content\/uploads\/2022\/06\/index-files-nginx-1024x75.jpg 1024w, https:\/\/raspberrytips.com\/wp-content\/uploads\/2022\/06\/index-files-nginx-768x56.jpg 768w\" sizes=\"auto, (max-width: 1132px) 100vw, 1132px\" \/><\/li>\n\n\n\n<li><strong>In the same file, find these lines:<\/strong><br><img loading=\"lazy\" decoding=\"async\" width=\"800\" height=\"264\" class=\"wp-image-47357\" style=\"width: 800px;\" src=\"https:\/\/raspberrytips.com\/wp-content\/uploads\/2022\/06\/php_version_nginx_bad.jpg\" alt=\"\" srcset=\"https:\/\/raspberrytips.com\/wp-content\/uploads\/2022\/06\/php_version_nginx_bad.jpg 792w, https:\/\/raspberrytips.com\/wp-content\/uploads\/2022\/06\/php_version_nginx_bad-300x99.jpg 300w, https:\/\/raspberrytips.com\/wp-content\/uploads\/2022\/06\/php_version_nginx_bad-768x253.jpg 768w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><\/li>\n\n\n\n<li><strong>Uncomment and change them to look like this<\/strong>: <br><img loading=\"lazy\" decoding=\"async\" width=\"800\" height=\"158\" class=\"wp-image-47356\" style=\"width: 800px;\" src=\"https:\/\/raspberrytips.com\/wp-content\/uploads\/2022\/06\/nginx_php_fastcgi_good.jpg\" alt=\"\" srcset=\"https:\/\/raspberrytips.com\/wp-content\/uploads\/2022\/06\/nginx_php_fastcgi_good.jpg 768w, https:\/\/raspberrytips.com\/wp-content\/uploads\/2022\/06\/nginx_php_fastcgi_good-300x59.jpg 300w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><br>(Pay close attention to how <em>php-fpm.sock<\/em> is entered.)<\/li>\n\n\n\n<li><strong>Save and exit<\/strong> (CTRL+O, CTRL+X)<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Restart Nginx to apply the changes:<br><\/strong><code>sudo systemctl restart nginx<\/code><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Now, let&#8217;s create a test php file under <em>\/var\/ww\/html<\/em> to check if it&#8217;s working correctly.<br>Here&#8217;s a simple example of what to put inside your <em>test.php<\/em> file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\nphpinfo();\n?&gt;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">After you save, you should now be able access it via your browser (<em>http:\/\/IP\/test.php<\/em>).<br>If PHP is being processed with Nginx correctly, you should get served a page like this:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1188\" height=\"352\" src=\"https:\/\/raspberrytips.com\/wp-content\/uploads\/2022\/06\/php_version_nginx.jpg\" alt=\"\" class=\"wp-image-47355\" srcset=\"https:\/\/raspberrytips.com\/wp-content\/uploads\/2022\/06\/php_version_nginx.jpg 1188w, https:\/\/raspberrytips.com\/wp-content\/uploads\/2022\/06\/php_version_nginx-300x89.jpg 300w, https:\/\/raspberrytips.com\/wp-content\/uploads\/2022\/06\/php_version_nginx-1024x303.jpg 1024w, https:\/\/raspberrytips.com\/wp-content\/uploads\/2022\/06\/php_version_nginx-768x228.jpg 768w\" sizes=\"auto, (max-width: 1188px) 100vw, 1188px\" \/><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">You can now use PHP code in any of your web pages.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">MySQL Installation<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>A MySQL server is often used alongside PHP to store data on the server<\/strong>. For example, the tutorials written on this website are all stored in a database. When you access a specific URL, PHP will request from the MySQL server to find the corresponding text to display.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To use MySQL with Nginx, you first need to <a rel=\"noopener\" href=\"https:\/\/raspberrytips.com\/install-mariadb-raspberry-pi\/\" data-type=\"post\" data-id=\"3265\" target=\"_blank\" data-lasso-id=\"3395\">install a MySQL server on your Raspberry Pi<\/a>. I have a full guide about this, so I&#8217;ll let you click on the link and follow the other tutorial first. I will only focus here on how to user MySQL functions with PHP on a Nginx server.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The process is the same as with another web server, you just need to install one PHP module:<br><code>sudo apt install php-mysql<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Once done, you can now use MySQL functions in your code. Check <a rel=\"noopener\" data-lasso-id=\"3396\" href=\"https:\/\/www.w3schools.com\/php\/func_mysqli_query.asp\" target=\"_blank\">this tutorial on W3Schools<\/a> if you don&#8217;t know how to do this.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">MySQL is not your only option, you can find the <a href=\"https:\/\/raspberrytips.com\/best-database-raspberry-pi\/\" data-type=\"post\" data-id=\"11883\" target=\"_blank\" rel=\"noreferrer noopener\">best database servers for Raspberry Pi<\/a> here, and use it with Nginx. But MySQL\/MariaDB is often the default choice for a web server.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">That&#8217;s all for today&#8217;s tutorial. If you later decide you want to open your web server to the broader internet, find out how to do so safely with <a href=\"https:\/\/raspberrytips.com\/cloudflare-selfhosted-website\/\" data-type=\"link\" data-id=\"https:\/\/raspberrytips.com\/cloudflare-selfhosted-website\/\">Raspberry Pi &amp; Cloudflare Tunnel<\/a>.<br><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">FAQ<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Apache vs Nginx: Which one is better on Raspberry Pi?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Overall, Nginx offers better performance and can handle more simultaneous connections than Apache.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For small projects, I would recommend using the web server you&#8217;re most familiar with. But if you have a Raspberry Pi with less than 512M of RAM or a single-core CPU (Pi Zero or older ones, for instance), testing Nginx might be a good idea. The same goes for bigger projects, with many requests at the same time.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I tend to prefer Apache because I&#8217;m used to it, but in theory, Nginx is often a better choice.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Can I run Python code with Nginx?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">By default, Nginx doesn&#8217;t know how to run Python scripts. As for PHP, using fastgci_pass in the default configuration is required to use Python code on your Nginx server.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Another way could be to <a rel=\"noopener\" href=\"https:\/\/pythonbasics.org\/webserver\/\" target=\"_blank\" data-lasso-id=\"3397\">start a Python web server<\/a> on another port, and use the Nginx proxy feature to redirect HTTP requests to this port. I&#8217;m not sure however is Nginx is really useful in this case, you can just use the Python web server directly.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If your new website is important, like with real traffic from remote users (not only you), it&#8217;s probably a good idea to put something in place to monitor it. You can read my article on the topic here: <a href=\"https:\/\/raspberrytips.com\/monitor-a-website-on-raspberry-pi\/\" data-type=\"post\" data-id=\"12579\">The Definitive Guide to Monitor a Website on Raspberry Pi<\/a>.<\/p>\n\n\n<section id=\"end-block-pi\">\r\n<div class=\"rt-community-card \">\r\n\t<div class=\"rt-community-card__inner\">\r\n\r\n\t\t<div class=\"rt-community-card__main\">\r\n\t\t\t<h3 class=\"rt-community-card__headline\">\r\n\t\t\t\tNot getting the same result?\t\t\t<\/h3>\r\n\r\n\t\t\t<p class=\"rt-community-card__description\">\r\n\t\t\t\tEven when you follow every step, small differences in OS version, hardware or config can change the outcome. Instead of wasting time guessing, get help from people who have already fixed the same kind of issue.\t\t\t<\/p>\r\n\r\n\t\t\t<div class=\"rt-community-card__actions\">\r\n\t\t\t\t<a class=\"rt-community-card__button\" href=\"https:\/\/raspberrytips.com\/school\/community\/?coupon=EBCTY\">\r\n\t\t\t\t\t<span>Ask your question now<\/span>\r\n\t\t\t\t\t<span class=\"rt-community-card__button-arrow\">\u2192<\/span>\r\n\t\t\t\t<\/a>\r\n\r\n\t\t\t\t\t\t\t\t\t<div class=\"rt-community-card__small\">\r\n\t\t\t\t\t\t<span class=\"rt-community-card__small-lock\">\ud83d\udd12<\/span>\r\n\t\t\t\t\t\tNo risk. Cancel anytime.\t\t\t\t\t<\/div>\r\n\t\t\t\t\t\t\t<\/div>\r\n\t\t<\/div>\r\n\r\n\t\t\t\t\t<div class=\"rt-community-card__side\">\r\n\t\t\t\t<ul class=\"rt-community-card__benefits\">\r\n\t\t\t\t\t\t\t\t\t\t\t<li>Get help on your exact issue<\/li>\r\n\t\t\t\t\t\t\t\t\t\t\t<li>Access step-by-step videos for tricky setups<\/li>\r\n\t\t\t\t\t\t\t\t\t\t\t<li>Browse the website without ads<\/li>\r\n\t\t\t\t\t\t\t\t\t<\/ul>\r\n\t\t\t<\/div>\r\n\t\t\r\n\t<\/div>\r\n<\/div>\r\n<\/section>\r\n\r\n<style>\r\n.rt-community-card {\r\n\t--rt-bg: #f7f7f9;\r\n\t--rt-border: #e4e4e8;\r\n\t--rt-text: #15171b;\r\n\t--rt-muted: #5b6270;\r\n\t--rt-accent: #C61E4A;\r\n\t--rt-accent-hover: #aa183f;\r\n\t--rt-shadow: 0 12px 30px rgba(0, 0, 0, 0.06);\r\n\r\n\tmargin: 36px 0;\r\n\tcolor: var(--rt-text);\r\n\tfont-family: inherit;\r\n}\r\n\r\n.rt-community-card__inner {\r\n\tdisplay: grid;\r\n\tgrid-template-columns: minmax(0, 1.55fr) minmax(260px, 0.95fr);\r\n\tgap: 34px;\r\n\talign-items: start;\r\n\tbackground: var(--rt-bg);\r\n\tborder: 1px solid var(--rt-border);\r\n\tborder-radius: 22px;\r\n\tpadding: 34px 36px;\r\n\tbox-shadow: var(--rt-shadow);\r\n}\r\n\r\n.rt-community-card__main {\r\n\tmin-width: 0;\r\n}\r\n\r\n.rt-community-card__side {\r\n\tborder-left: 1px solid #e1e1e6;\r\n\tpadding-left: 28px;\r\n}\r\n\r\n.rt-community-card__benefits {\r\n\tmargin: 6px 0 0;\r\n\tpadding: 0;\r\n\tlist-style: none;\r\n\tdisplay: grid;\r\n\tgap: 18px;\r\n}\r\n\r\n.rt-community-card__benefits li {\r\n\tposition: relative;\r\n\tpadding-left: 18px;\r\n\tfont-size: 18px;\r\n\tline-height: 1.55;\r\n\tcolor: var(--rt-text);\r\n}\r\n\r\n.rt-community-card__benefits li::before {\r\n\tcontent: \"\";\r\n\tposition: absolute;\r\n\tleft: 0;\r\n\ttop: 0.72em;\r\n\twidth: 7px;\r\n\theight: 7px;\r\n\tborder-radius: 999px;\r\n\tbackground: var(--rt-accent);\r\n\ttransform: translateY(-50%);\r\n}\r\n\r\n.rt-community-card__actions {\r\n\tdisplay: flex;\r\n\tflex-direction: column;\r\n\talign-items: flex-start;\r\n\tgap: 10px;\r\n\tmargin-top: 30px;\r\n}\r\n\r\n.rt-community-card__button {\r\n\tdisplay: inline-flex;\r\n\talign-items: center;\r\n\tjustify-content: center;\r\n\tgap: 10px;\r\n\tmin-height: 60px;\r\n\tpadding: 0 28px;\r\n\tborder-radius: 14px;\r\n\tbackground: var(--rt-accent);\r\n\tcolor: #fff !important;\r\n\ttext-decoration: none !important;\r\n\tfont-size: 21px;\r\n\tfont-weight: 700;\r\n\tline-height: 1;\r\n\tbox-shadow: 0 12px 22px rgba(198, 30, 74, 0.22);\r\n\ttransition: background .2s ease, transform .2s ease, box-shadow .2s ease;\r\n}\r\n\r\n.rt-community-card__button:hover {\r\n\tbackground: var(--rt-accent-hover);\r\n\tcolor: #fff !important;\r\n\ttransform: translateY(-1px);\r\n\tbox-shadow: 0 14px 26px rgba(198, 30, 74, 0.28);\r\n}\r\n\r\n.rt-community-card__button-arrow {\r\n\tfont-size: 20px;\r\n\tline-height: 1;\r\n}\r\n\r\n.rt-community-card__small {\r\n\tfont-size: 15px;\r\n\tline-height: 1.5;\r\n\tcolor: #6a717d;\r\n\tpadding-left: 2px;\r\n}\r\n\r\n.rt-community-card__small-lock {\r\n\tmargin-right: 6px;\r\n\tfont-size: 14px;\r\n\tvertical-align: baseline;\r\n}\r\n\r\n\/* Tablet *\/\r\n@media (max-width: 900px) {\r\n\t.rt-community-card {\r\n\t\tmargin: 28px 0;\r\n\t}\r\n\r\n\t.rt-community-card__inner {\r\n\t\tgrid-template-columns: 1fr;\r\n\t\tgap: 24px;\r\n\t\tpadding: 28px 24px;\r\n\t}\r\n\r\n\t.rt-community-card__side {\r\n\t\tborder-left: 0;\r\n\t\tborder-top: 1px solid #e1e1e6;\r\n\t\tpadding-left: 0;\r\n\t\tpadding-top: 22px;\r\n\t}\r\n\r\n\t.rt-community-card__benefits {\r\n\t\tgrid-template-columns: 1fr;\r\n\t\tgap: 12px;\r\n\t}\r\n}\r\n\r\n\/* Mobile *\/\r\n@media (max-width: 640px) {\r\n\t.rt-community-card__inner {\r\n\t\tpadding: 22px 18px;\r\n\t\tborder-radius: 18px;\r\n\t\tgap: 20px;\r\n\t}\r\n\t\r\n\t.rt-community-card__side {\r\n\t\tpadding-top: 18px;\r\n\t}\r\n\r\n\t.rt-community-card__benefits li {\r\n\t\tfont-size: 16px;\r\n\t}\r\n\r\n\t.rt-community-card__actions {\r\n\t\tmargin-top: 24px;\r\n\t\talign-items: stretch;\r\n\t}\r\n\r\n\t.rt-community-card__button {\r\n\t\twidth: 100%;\r\n\t\tmin-height: 56px;\r\n\t\tfont-size: 18px;\r\n\t\tpadding: 0 20px;\r\n\t}\r\n\r\n\t.rt-community-card__small {\r\n\t\ttext-align: center;\r\n\t\tpadding-left: 0;\r\n\t}\r\n}\r\n<\/style>\r\n\t\r\n","protected":false},"excerpt":{"rendered":"<p>Nginx is primarily a web server, but can also be used as a proxy server. It&#8217;s free, open-source and often in direct competition with Apache to build web applications. As a web developer, I&#8217;m more used to Apache, but Nginx is known to be almost 3 times faster and lighter, which is great for a&#8230;<\/p>\n","protected":false},"author":1,"featured_media":11611,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_kad_blocks_custom_css":"","_kad_blocks_head_custom_js":"","_kad_blocks_body_custom_js":"","_kad_blocks_footer_custom_js":"","_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","footnotes":""},"categories":[2],"tags":[],"class_list":["post-11608","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-how-to-tutorials"],"taxonomy_info":{"category":[{"value":2,"label":"How-To Tutorials"}]},"featured_image_src_large":["https:\/\/raspberrytips.com\/wp-content\/uploads\/2022\/06\/nginx-raspberry-pi-1024x683.jpg",1024,683,true],"author_info":{"display_name":"Patrick Fromaget","author_link":"https:\/\/raspberrytips.com\/author\/admin\/"},"comment_info":0,"category_info":[{"term_id":2,"name":"How-To Tutorials","slug":"how-to-tutorials","term_group":0,"term_taxonomy_id":2,"taxonomy":"category","description":"","parent":0,"count":228,"filter":"raw","cat_ID":2,"category_count":228,"category_description":"","cat_name":"How-To Tutorials","category_nicename":"how-to-tutorials","category_parent":0}],"tag_info":false,"_links":{"self":[{"href":"https:\/\/raspberrytips.com\/wp-json\/wp\/v2\/posts\/11608","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/raspberrytips.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/raspberrytips.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/raspberrytips.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/raspberrytips.com\/wp-json\/wp\/v2\/comments?post=11608"}],"version-history":[{"count":18,"href":"https:\/\/raspberrytips.com\/wp-json\/wp\/v2\/posts\/11608\/revisions"}],"predecessor-version":[{"id":53859,"href":"https:\/\/raspberrytips.com\/wp-json\/wp\/v2\/posts\/11608\/revisions\/53859"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/raspberrytips.com\/wp-json\/wp\/v2\/media\/11611"}],"wp:attachment":[{"href":"https:\/\/raspberrytips.com\/wp-json\/wp\/v2\/media?parent=11608"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/raspberrytips.com\/wp-json\/wp\/v2\/categories?post=11608"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/raspberrytips.com\/wp-json\/wp\/v2\/tags?post=11608"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}