Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
development:deploy:nginx [2020/04/16 11:13]
kalenpw [Nginx]
development:deploy:nginx [2021/07/06 09:48] (current)
kalenpw
Line 1: Line 1:
 ====== Nginx ====== ====== Nginx ======
 +
 +----
 +===== Example Server Blocks =====
 +Note: These are messy and need cleaned up. Don't blindly copy-paste may be errors.
   * [[.nginx : dokuwiki | Dokuwiki ]]   * [[.nginx : dokuwiki | Dokuwiki ]]
 +  * [[.nginx: laravel | Laravel ]]
 +  * [[.nginx: react | React ]]
   * [[.nginx : rocketchat | Rocket.Chat ]]   * [[.nginx : rocketchat | Rocket.Chat ]]
 +  * [[.nginx: vue | Vue ]] 
  
 +----
 +===== Config =====
 +** Caching **
 +<code nginx>
 +location /_assets {
 +    expires 30d;
 +    root /web/kalen.pw;
 +}
 +</code>
  
-Note: These are messy and need cleaned up\\ 
-TODO: add example configs 
 ---- ----
-===== Example Server Blocks ===== +**http2** \\ 
-** Laravel **+Only works with TLS and modern browsers (though 95%+ usage)
 <code nginx> <code nginx>
 server { server {
-  listen 80; +    listen 443 http2 ssl
-  server_name www.switchart.tk switchart.tk; +    ...
-    +
-  root /web/switchart.tk/public; +
-  index index.php index.html; +
-    +
-  location / { +
-    try_files $uri $uri/ /index.php?query_string; +
-  } +
-   +
-  location ~ \.php$ { +
-    #include snippets/fastcgi-php.conf; +
-    fastcgi_pass unix:/run/php/php7.2-fpm.sock; +
-    fastcgi_index index.php; +
-    fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; +
-    include fastcgi_params; +
-  } +
-   +
-  location ~ /\.(?!well-known).*{ +
-    deny all; +
-  } +
-  error_page 404 /404.html;+
 } }
 </code> </code>
-** React ** 
-<code nginx> 
-server { 
-    listen 80 default_server; 
-    server_name www.schedukal.ml schedukal.ml; 
  
-    root /web/schedukal.ml; +---- 
-    index index.php index.html;+**Reverse Proxy** \\ 
 +Useful for services that run on abnormal ports, but you want to have clean urls to access them
  
 +<file nginx reverse_proxy.conf>
 +server {
 +    server_name example.domain.com;
     location / {     location / {
-        try_files $uri /index.html;+        proxy_pass http://127.0.0.1:8000;
     }     }
 +}
 +</file>
 +----
  
-    location ~ \.php$ { +** Redirect all URLs to root** \
-        fastcgi_pass unix:/run/php/php7.2-fpm.sock; +Used, for example, on kalen.pw so any non-found files are redirected to the homepage (as opposed to serving a 404) 
-        fastcgi_index index.php; +<code nginx> 
-        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; +location / { 
-        include fastcgi_params;+    if (!-e $request_filename) { 
 +        rewrite ^ / permanent;
     }     }
- 
-    location ~ /\.(?!well-known).*{ 
-        deny all; 
-    } 
-    error_page 404 /404.html; 
- 
-    listen 443 ssl; # managed by Certbot 
-    ssl_certificate /etc/letsencrypt/live/kalen.pw/fullchain.pem; # managed by Certbot 
-    ssl_certificate_key /etc/letsencrypt/live/kalen.pw/privkey.pem; # managed by Certbot 
-    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot 
-    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot 
 } }
 </code> </code>
-** Vue ** +----
-<code nginx> +
-server { +
-    listen 80; +
-    listen 443 ssl; # managed by Certbot +
-    server_name www.kalen.pw kalen.pw;+
  
-    root /web/kalen.pw; 
-    index index.php index.html;     
- 
-    location ~ \.php$ { 
-        include snippets/fastcgi-php.conf; 
-        fastcgi_pass unix:/run/php/php7.0-fpm.sock; 
-    } 
- 
-    error_page 404 /404.html; 
-    ssl_certificate /etc/letsencrypt/live/kalen.pw/fullchain.pem; # managed by Certbot 
-    ssl_certificate_key /etc/letsencrypt/live/kalen.pw/privkey.pem; # managed by Certbot 
-    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot 
- 
-    #if ($scheme != "https") { 
-    #    return 301 https://$host$request_uri; 
-    #} # managed by Certbot 
-} 
-</code>