Answers.Body: <p>Typically a webserver knows how to serve static/already existing files just fine but Craft (and other CMS for that matter) are dealing with things like <code>/my-entry</code> or whatever that don't actually &quot;exist&quot; on the filesystem, which is why you're getting a 404 error. So we need to tell nginx how to serve those sorts of requests.</p>
  <p>The main thing you'll want to edit is near the top under <code>location / {</code>. It should be:</p>
  <pre><code>location / {
          try_files $uri $uri/ /index.php?$query_string;
      }
  </code></pre>
  <p>So now when a request comes in, nginx will see if a request is actually a file that already exists and since it is not, pass it back to PHP.</p>
  <p>That will Craft working. If you're doing localization or other things, you may need to tweak your config a bit.</p>
  <p>When you hit production you may want to look for more <a href="https://craftcms.stackexchange.com/questions/961/what-is-the-recommended-nginx-configuration-for-craft">robust configs</a> that will deal with turning off logging for static files, effective headers for caching, etc.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-08-23T18:48:29.130Z
Answers.Text: Thank you very much for the assistance! Through this, I got better acquainted with how the nginx config works, and was able to get everything up and running.
Answers.UserDisplayName: M Smith
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-08-24T19:57:12.090Z
Answers.Text: Great - You bet!
Answers.UserDisplayName: RitterKnight
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-08-02T13:54:13.300Z
Answers.LastActivityDate: 2022-08-02T13:54:13.300Z
Answers.UserDisplayName: RitterKnight
Body: <p>Attempting to update an Azure Linux Web App to Craft 4. So I updated the Linux Web App to PHP 8. But now it’s using Nginx instead of Apache (would have been nice to know they change that when you switch PHP versions...)</p>
  <p>Craft installed fine from the command line, and is running. But the default Nginx config from Azure returns 404 errors. Here is the default config. How can I fix it to get Craft to work?</p>
  <pre><code>server {
      #proxy_cache cache;
          #proxy_cache_valid 200 1s;
      listen 8080;
      listen [::]:8080;
      root /home/site/wwwroot;
      index  index.php index.html index.htm;
      server_name  example.com www.example.com; 
  
      location / {            
          index  index.php index.html index.htm hostingstart.html;
      }
  
      # redirect server error pages to the static page /50x.html
      #
      error_page   500 502 503 504  /50x.html;
      location = /50x.html {
          root   /html/;
      }
      
      # Disable .git directory
      location ~ /\.git {
          deny all;
          access_log off;
          log_not_found off;
      }
  
      # Add locations of phpmyadmin here.
      location ~ [^/]\.php(/|$) {
          fastcgi_split_path_info ^(.+?\.php)(|/.*)$;
          fastcgi_pass 127.0.0.1:9000;
          include fastcgi_params;
          fastcgi_param HTTP_PROXY &quot;&quot;;
          fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
          fastcgi_param PATH_INFO $fastcgi_path_info;
          fastcgi_param QUERY_STRING $query_string;
          fastcgi_intercept_errors on;
          fastcgi_connect_timeout         300; 
          fastcgi_send_timeout           3600; 
          fastcgi_read_timeout           3600;
          fastcgi_buffer_size 128k;
          fastcgi_buffers 4 256k;
          fastcgi_busy_buffers_size 256k;
          fastcgi_temp_file_write_size 256k;
      }
  }
  </code></pre>
  
Tags: <php><nginx>
Title: Configuring Nginx with Azure Linux Web App (PHP 8, Craft 4)
ThreadText: # Configuring Nginx with Azure Linux Web App (PHP 8, Craft 4)
  
  (Asked by: username_0 on 2022-08-01)
  
  Attempting to update an Azure Linux Web App to Craft 4. So I updated the Linux Web App to PHP 8. But now it’s using Nginx instead of Apache (would have been nice to know they change that when you switch PHP versions...)
  
  Craft installed fine from the command line, and is running. But the default Nginx config from Azure returns 404 errors. Here is the default config. How can I fix it to get Craft to work?
  
  ```
  server {
      #proxy_cache cache;
          #proxy_cache_valid 200 1s;
      listen 8080;
      listen [::]:8080;
      root /home/site/wwwroot;
      index  index.php index.html index.htm;
      server_name  example.com www.example.com; 
  
      location / {            
          index  index.php index.html index.htm hostingstart.html;
      }
  
      # redirect server error pages to the static page /50x.html
      #
      error_page   500 502 503 504  /50x.html;
      location = /50x.html {
          root   /html/;
      }
      
      # Disable .git directory
      location ~ /\.git {
          deny all;
          access_log off;
          log_not_found off;
      }
  
      # Add locations of phpmyadmin here.
      location ~ [^/]\.php(/|$) {
          fastcgi_split_path_info ^(.+?\.php)(|/.*)$;
          fastcgi_pass 127.0.0.1:9000;
          include fastcgi_params;
          fastcgi_param HTTP_PROXY "";
          fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
          fastcgi_param PATH_INFO $fastcgi_path_info;
          fastcgi_param QUERY_STRING $query_string;
          fastcgi_intercept_errors on;
          fastcgi_connect_timeout         300; 
          fastcgi_send_timeout           3600; 
          fastcgi_read_timeout           3600;
          fastcgi_buffer_size 128k;
          fastcgi_buffers 4 256k;
          fastcgi_busy_buffers_size 256k;
          fastcgi_temp_file_write_size 256k;
      }
  }
  
  ```
  
  **Tags:** php, nginx
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2022-08-02. Score: 1 | Accepted answer
  
  Typically a webserver knows how to serve static/already existing files just fine but Craft (and other CMS for that matter) are dealing with things like `/my-entry` or whatever that don't actually "exist" on the filesystem, which is why you're getting a 404 error. So we need to tell nginx how to serve those sorts of requests.
  
  The main thing you'll want to edit is near the top under `location / {`. It should be:
  
  ```
  location / {
          try_files $uri $uri/ /index.php?$query_string;
      }
  
  ```
  
  So now when a request comes in, nginx will see if a request is actually a file that already exists and since it is not, pass it back to PHP.
  
  That will Craft working. If you're doing localization or other things, you may need to tweak your config a bit.
  
  When you hit production you may want to look for more [robust configs](https://craftcms.stackexchange.com/questions/961/what-is-the-recommended-nginx-configuration-for-craft) that will deal with turning off logging for static files, effective headers for caching, etc.
  
  > **Comments:**
  > **username_0**: Thank you very much for the assistance! Through this, I got better acquainted with how the nginx config works, and was able to get everything up and running.  
  > **username_1**: Great - You bet!  
  
  ---
  
  