StarfighterZorg

Caddyfile (v0.9.x) - Reverse Proxy Usenet Apps Example

Aug 17th, 2016
7,901
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Nginx 9.94 KB | None | 0 0
  1. ############################ Can't test all of the code for every app below so use as a reference only! ###########################
  2.  
  3. # Notes:    (Deprecated!)
  4.  
  5. # Make sure all your apps are setup/compatible with Base URL's and have all their settings configured to work with reverse proxies
  6. # Make sure to change the port #'s to match your apps especially if the're not the default ones
  7. # Included FastCGI code.... revised and should make things easier for Windows users
  8. # Also this config includes a lot of extra code that isn't necessarily required so omit the things you don't want or care about
  9.  
  10. # Edit 1:  Fixed some things and added more comments, whether they help....?
  11.  
  12. # Edit 2:  Looks like Caddy is deprecating "proxy_header" directives and moving to "header_upstream" & "header_downstream" instead
  13. #          New code should work with Caddy v0.9+
  14. #          Replaced old "proxy_header" code with new "transparent" preset which inherently includes the following directives:
  15. #               header_upstream Host {host}
  16. #               header_upstream X-Real-IP {remote}
  17. #               header_upstream X-Forwarded-For {remote}
  18. #               header_upstream X-Forwarded-Proto {scheme}
  19.            
  20. # Edit 3:  Added code to get Glances monitoring tool working with Caddy and also a way to secure it with the "basicauth" directive
  21.  
  22. # Edit 4:  Added code at bottom to serve the apps over localhost on port 80
  23.  
  24. # Edit 5:  Getting PHP up and running on Windows is super simple now that Caddy can start the php-cgi server itself
  25.  
  26. #          You basically just need to download PHP and put the folder in Caddy's root directory and use the new code
  27. #          http://windows.php.net/download/
  28.  
  29. #          Newer builds of PHP require Visual C++ Redistributable for Visual Studio installed.
  30. #          Choose which PHP version you want and install the corresponding VC++ package if not already installed on your system
  31.  
  32. #          PHP 7.x built with (VC14)
  33. #          https://www.microsoft.com/en-us/download/details.aspx?id=48145
  34.  
  35. #          PHP 5.6 built with (VC11)
  36. #          http://www.microsoft.com/en-us/download/details.aspx?id=30679
  37.  
  38. # Edit 6:  Added Emby location and web addresses to each app
  39.  
  40. # Edit 7:  Added Deluge location (Optimized the rewrite statement + fixed code so it would work over domain and localhost)
  41.  
  42. # Edit 8:  Cleaned up Deluge code to make it less ubiquitous and less reliant on domain/localhost
  43.  
  44. # Edit 9:  Added rewrite code to deal with 404 error when trying to load glances.png
  45.  
  46. # Edit 10: Someone found a simpler way to get Deluge working on the Caddy Forums
  47.  
  48. # Edit 11: Removed the extra "header_upstream X-Forwarded-Host {host}" code from every location except PlexPy!
  49.  
  50. # Edit 12: Added location & GitHub address to new movie downloader app called Watcher
  51.  
  52. # Edit 13: Added location & GitHub address to new movie downloader app called Radarr (fork of Sonarr for movies)
  53.  
  54. # Edit 14: Removed the rewrite to add trailing "/" for NZBHydra & Ombi since it's not needed it seems
  55.  
  56. # Edit 15: Updated PlexRequests.Net to it's new name (Ombi) and GitHub address
  57.  
  58. # Edit 16: Updated and streamlined code for fastcgi, gzip and a few other sections, removed "http://" from all addresses
  59.  
  60. # Edit 17: Adding URL's for Caddy Server, Forum & User Guide:
  61. #          https://caddyserver.com/
  62. #          https://caddyserver.com/docs
  63. #          https://forum.caddyserver.com/
  64.  
  65. # Edit 18: Added example for Plex subdomain! You can use subdomains instead of subfolders for all your apps if you prefer
  66.  
  67. # Edit 19: Updated PlexPy's GitHub address. The "header_upstream X-Forwarded-Host {host}" is only needed in SSL/HTTPS domain block
  68. #          The dev is going to rename PlexPy eventually so will update name when official
  69.  
  70. # Edit 20: Added link to Visual C++ download since newer PHP versions require it!  Look at the "Edit 5" section above!
  71.  
  72. # Edit 21: Watcher is now deprecated and dev is rewriting it to work with Python 3.x (Watcher3), updated GitHub address
  73.  
  74. # Edit 22: Organizr is a nice php Dashboard to help organize your apps! https://github.com/causefx/Organizr
  75. #          Alternative Dashboard is Muximux! https://github.com/mescon/Muximux
  76.  
  77. # Edit 23: Was getting some 502 Bad Gateway errors with php seeming to crash after a while using Organizr...?
  78.          
  79. #          Added some PHP arguments to Windows - "Environment Variables" to see if it would help?
  80. #          Only works with PHP v7.1+ on "Windows" - (PHP 5.x/7.0 doesn't support these arguments on "Windows" it seems)
  81. #          This would allow for 2 extra fastcgi spawns and would recycle fastcgi after 100 requests
  82.  
  83. #          PHP_FCGI_CHILDREN
  84. #          2
  85.            
  86. #          PHP_FCGI_MAX_REQUESTS
  87. #          100
  88.  
  89. # Edit 24: The 2 arguments above seems to have solved the random PHP crashes with Organizr's Homepage so far
  90.  
  91. # Edit 25: Don't update to Caddy v0.10.x until the proxy directive using "without" get's fixed or Glances will not work
  92. #          https://github.com/mholt/caddy/issues/1604
  93.  
  94. #          You could always just use a subdomain for Glances as an alternative!
  95.  
  96. # Edit 26: Proxying should be fixed in v0.10.1 and safe to upgrade.......?
  97.  
  98. #          Some of the syntax has/will change in v0.10.x and I'll create a new pastebin going forward
  99. #          New Caddyfile code is short and will import most of the directives from a separate file called "common.conf"
  100.  
  101. #               Caddyfile:      https://pastebin.com/bLVJ4vsN
  102. #               Common.conf:    https://pastebin.com/hdDKbcSV
  103.  
  104.  
  105. ####################################################### Code starts below ########################################################
  106.  
  107. yourdomain.com {                       
  108.  
  109.     ext .html .htm .php
  110.     root /caddy/www                     # Windows location, change it to where the html root is on your system/OS
  111.    
  112.     # Gzip will compress files to speedup/minimize the size of data transferred but not 100% necessary
  113.    
  114.     gzip
  115.    
  116.     tls myname@emailprovider.com        # Email for Let's Encrypt Verification
  117.    
  118.     # Having logs enabled can provide useful information about your setup but not 100% necessary
  119.  
  120.     log /caddy/access.log {
  121.     rotate {
  122.         size 5          # Rotate after 5 MB
  123.         age  7          # Keep log files for 7 days
  124.         keep 2          # Keep at most 2 log files
  125.         }
  126.     }
  127.    
  128.     # This errors block is great when first testing out your setup but not needed and can be omitted entirely
  129.  
  130.     errors {
  131.     log /caddy/error.log {
  132.         size 5          # Set max size 5 MB
  133.         age  7          # Keep log files for 7 days
  134.         keep 2          # Keep at most 2 log files
  135.         }
  136.     }
  137.  
  138.     # This header block below will provide you with some extra security, not 100% necessary but better safe then sorry
  139.  
  140.     header / { 
  141.         X-Content-Type-Options nosniff
  142.         X-XSS-Protection "1; mode=block"
  143.         Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
  144.     }
  145.    
  146.     # You can normally use "127.0.0.1", use "Host IP" address if your running the web server or the apps on different machines
  147.  
  148.     proxy /sabnzb 127.0.0.1:8080 {          # https://sabnzbd.org/
  149.         transparent
  150.     }
  151.  
  152.     proxy /htpc 127.0.0.1:8085 {            # http://htpc.io/
  153.         transparent
  154.     }
  155.  
  156.     proxy /headphones 127.0.0.1:8181 {      # https://github.com/rembo10/headphones
  157.         transparent
  158.     }
  159.  
  160.     proxy /mylar 127.0.0.1:8090 {           # https://github.com/evilhero/mylar
  161.         transparent
  162.     }
  163.  
  164.     proxy /lazy 127.0.0.1:5299 {            # https://github.com/DobyTang/LazyLibrarian
  165.         transparent
  166.     }
  167.  
  168.     proxy /emby 127.0.0.1:8096 {            # https://emby.media/
  169.         transparent
  170.     }
  171.    
  172.     proxy /sonarr 127.0.0.1:8989 {          # https://sonarr.tv/
  173.         transparent
  174.     }
  175.  
  176.     # Headphones uses port 8181 so make sure there's no conflict!
  177.  
  178.     proxy /plexpy 127.0.0.1:8181 {          # https://github.com/JonnyWong16/plexpy
  179.         header_upstream X-Forwarded-Host {host}
  180.         transparent
  181.     }
  182.  
  183.     proxy /nzbget 127.0.0.1:6789 {          # http://nzbget.net/
  184.         transparent
  185.     }
  186.  
  187.     proxy /couch 127.0.0.1:5050 {           # https://couchpota.to/
  188.         transparent
  189.     }
  190.  
  191.     proxy /nzbhydra 127.0.0.1:5075 {        # https://github.com/theotherp/nzbhydra
  192.         transparent
  193.     }
  194.  
  195.     proxy /ombi 127.0.0.1:3579 {            # https://github.com/tidusjar/Ombi
  196.         transparent
  197.     }
  198.  
  199.     # The rewrite makes sure all of glances sub directory calls are proxied from domain to host
  200.  
  201.     rewrite {
  202.         if {>Referer} has /glances
  203.         to /glances/{path}
  204.     }
  205.  
  206.     # The code below gives you a tiny level of security requiring a username/password before Caddy will let you connect to it
  207.  
  208.     basicauth /glances Username Password
  209.    
  210.     proxy /glances 127.0.0.1:61208 {        # https://github.com/nicolargo/glances
  211.         without /glances
  212.         transparent
  213.     }
  214.  
  215.     proxy /deluge 127.0.0.1:8112 {          # http://deluge-torrent.org/
  216.         without /deluge
  217.         transparent
  218.         header_upstream X-Deluge-Base "/deluge"
  219.     }
  220.  
  221.     proxy /watcher 127.0.0.1:9090 {         # https://github.com/nosmokingbandit/Watcher3
  222.         transparent
  223.     }
  224.    
  225.     proxy /radarr 127.0.0.1:7878 {          # https://github.com/Radarr/Radarr
  226.         transparent
  227.     }
  228.  
  229.     # The new code below will startup the server & proxy PHP requests
  230.    
  231.     startup /caddy/php/php-cgi -b 127.0.0.1:9000 &
  232.     fastcgi / 127.0.0.1:9000 php
  233.  
  234. }
  235.  
  236.  
  237. # Adding the following code will allow you to serve the above over locahost
  238.  
  239. ####################################################################################
  240. # Localhost code block
  241. ####################################################################################
  242.  
  243. http://localhost {
  244.  
  245.     ext .html .htm .php
  246.     root /caddy/www                         # Windows location, change it to where the html root is on your system/OS
  247.    
  248.     gzip
  249.    
  250.     # Add all the apps you use below!! Only going to add one below as an example, just copy/paste code from above!
  251.     # The section below should be exactly like your what you have for your domain site!!
  252.    
  253.     proxy /sonarr 127.0.0.1:8989 {             
  254.         transparent
  255.     }
  256.  
  257.     # App 2 code etc.........
  258.  
  259.     # For localhost you just need to tell Caddy to pass PHP requests to the php-cgi server that you started above
  260.  
  261.     fastcgi / 127.0.0.1:9000 php
  262.  
  263. }
  264.  
  265.  
  266. ####################################################################################
  267. # Plex subdomain code block
  268. ####################################################################################
  269.  
  270. plex.yourdomain.com {
  271.  
  272. gzip
  273.  
  274.     proxy / 127.0.0.1:32400 {
  275.         transparent
  276.     }
  277.  
  278. }
Advertisement
Add Comment
Please, Sign In to add comment