خدمة Discourse من مجلد فرعي (بادئة مسار) بدلاً من النطاق الفرعي

:warning: Discourse Official Statement about Subfolder setup

We support subfolder setups for our hosted customers at the enterprise level and up. Due to heavy technical setup complexity we strongly recommend you do not use this setup unless you are very experienced in custom subfolder setups.

It is critical you have a deep understanding of

  • NGINX setup in the Discourse Docker container
  • Secure original IP forwarding using custom headers in the proxy chain
  • Rate limiting in front proxy server

If this all sounds odd and strange to you we strongly recommend you avoid this setup.

To serve Discourse from a subfolder (a.k.a. with a path prefix) on your domain, like https://www.example.com/=SUBFOLDER=, here’s how to do it!

Docker config

In the env section of your docker container yml file, add the DISCOURSE_RELATIVE_URL_ROOT setting with the subfolder you want to use. Make sure it does not end with a /.

Editing this will update the entire guide.

env:
  ...
  DISCOURSE_RELATIVE_URL_ROOT: /=SUBFOLDER=

The run section needs some changes to send all Discourse routes to the right place. Here is a complete run section with subfolder support:

run:
    - exec:
        cd: $home
        cmd:
          - mkdir -p public/=SUBFOLDER=
          - cd public/=SUBFOLDER= && ln -s ../uploads && ln -s ../backups
    - replace:
       global: true
       filename: /etc/nginx/conf.d/discourse.conf
       from: proxy_pass http://discourse;
       to: |
          rewrite ^/(.*)$ /=SUBFOLDER=/$1 break;
          proxy_pass http://discourse;
    - replace:
       filename: /etc/nginx/conf.d/discourse.conf
       from: etag off;
       to: |
          etag off;
          location /=SUBFOLDER= {
             rewrite ^/=SUBFOLDER=/?(.*)$ /$1;
          }
    - replace:
         filename: /etc/nginx/conf.d/discourse.conf
         from: $proxy_add_x_forwarded_for
         to: $http_your_original_ip_header
         global: true

$http_your_original_ip_header stands for Your-Original-Ip-Header, which is a trusted Header you set on the origin which contains the actual client IP.

This is required cause traffic passes through a central proxy, if Discourse happens to have a public IP you can spoof it. If Discourse is private you may be able to get away with X-Forwarded-For

After making these changes, bootstrap your Docker container as usual, or rebuild if you’re changing an existing container.

./launcher bootstrap app

or

./launcher rebuild app

Attached is a complete example yml file of a standalone container.

subfolder-sample.yml (3.1 KB)

Rate limiting concerns

If you are going for this setup you probably want to rate limit requests prior to them landing on NGINX in the container, that means you probably will avoid using our rate limiting template. It is very hard to configure NGINX in the container to limit on a remapped IP and would require complex changes to the template.

Existing posts

If you did this with an existing site that was on a subdomain, you’ll find that your uploads are broken. There’s a tool that can help fix all paths to include the subfolder. In the Discourse directory (typically /var/www/discourse'), run it like this after taking a backup:

RAILS_ENV=production bundle exec script/discourse remap '/uploads' '/=SUBFOLDER=/uploads'

See also: Use a subfolder (path prefix) to serve Discourse with multiple servers sharing a domain for more esoteric setups.

robots.txt

Now that Discourse is running on a subfolder, it cannot serve its robots.txt file to control which routes are crawled by web crawlers. Crawlers will be looking at your main site’s robots.txt file (https://www.example.com/robots.txt). You need to copy the contents of Discourse’s robots.txt file (found at https://www.example.com/=SUBFOLDER=/robots.txt) and put it in your main site’s robots.txt file.

35 إعجابًا
How can I change my installation from forum.website.com to www.website.com/forum?
Moving Discourse to subdirectory caused all uploads to break
Uploaded avatars and Gravatar not working with subfolder installation
Is it possible to install discourse inside a directory?
Launch Discourse on www.example.com/meta/ In a web folder type
404 errors (assets) on Subfolder installation
Subfolder with SSL and nginx reverse proxy
Non-standard port breaks uploads
Avatar uploads broken on subfolder installs?
Problem with discourse in a subfolder
Install Discourse as subfolder within Wordpress website?
Install Discourse into domain.com/forums
Image lightbox not working in subfolder install
Moving Discourse to subdirectory caused all uploads to break
Uploaded avatar or gravatar not working
Installation on v-server as a subfolder with other services in subfolders using apache
Is it possible to install Discourse on the same domain of your main website
Subfolder install - external links get changed/redirected to site relative links
Discourse embedded on my WP
Reverse Proxy Assets
Reverse Proxy rewrites domain in external links in posts
Inheriting discourse install - need some assistance
Multisite installation ... in subdirectories?
Generals Subfolder recommendations and tips
Add to route headers?
Sorry, there was an error authorizing your account
Site Logo and Icons Break due to subfolder config
Site Logo and Icons Break due to subfolder config
Site Logo and Icons Break due to subfolder config
404 errors (assets) on Subfolder installation
404 errors (assets) on Subfolder installation
Moving Discourse from Subdomain to Subfolder
Blank Page After installing Discourse on Subfolder
Trailing slash and subfolder setup
Install Discourse as a subdirectory with existing Nginx
How to run discourse on subdirectory of external domain?
How to run discourse on subdirectory of external domain?
How to run discourse on subdirectory of external domain?
Digest email issue with 'stable'
Using other ports than 80 and 443 - HowTo?
Add secondary url / embed into Wordpress
Recent Changes Breaking Subfolder Setup?
Issue with FAQ link on edge case subfolder setup
Issue with FAQ link on edge case subfolder setup
Put discourse on a sub url
No subfolder prefixing for some resources
Upgrade failed - could use some help to try and fix using SSH
How to run Discourse in a subfolder?
Install Discourse without docker with an existing Rails app
Docker subfolder install not working due to Ember-CLI proxy error?
Multisite DISCOURSE_RELATIVE_URL_ROOT
How to install discourse into subdirectory instead of subdomain?
Setup wizard emoji wrong in subfolder install
Not find a Gravatar
Installing for production via Docker on existing server with Litespeed?
Use a subfolder (path prefix) to serve Discourse with multiple servers sharing a domain
Configure a Cloudfront reverse proxy for a subfolder install
Run other websites on the same machine as Discourse
Embedding Categories in Existing SPA
Does custom domain support the subpath format like 'example.com/forum'?
To use Discourse completely on shopify
Are separate subdomains required for making a discourse forum?
Problem when updating Discourse Forum
Domain missing from some requests after migration from subfolder back to subdomain
Error when I send a message in chat [downgraded to Stable from 3.1.0beta4]
Error when I send a message in chat [downgraded to Stable from 3.1.0beta4]
How to Change Discourse forum path
How to setup NGINX in the Discourse Docker container
How to setup NGINX in the Discourse Docker container
Possible to update add url path prefix for /t and /c
Implement the discourse forum in the laravel 11 project
Endless loading behind Cloudflare
Publish Discourse under URL
Cloudflare with subfolder setup
Setup wizard emoji wrong in subfolder install
Discourse sign in redirects to root directory instead of subfolder
How to Set Up Discourse in a Subdirectory for Self-Hosting?
Last update breaks permalink for categories
Setup wizard emoji wrong in subfolder install
Ghost & Discourse SSO implementation
Wiki topics look incredibly out of date?
Too many redirects when reverse proxying to Discourse from a different server
Blank main page on one forum (subfolder + multisite install)
Moving Discourse to subdirectory caused all uploads to break
Feasible to reverse proxy using qualifier in URL?
Upgrade doesn't work when installed with subfolder
Setup Discourse with KeyCDN
Message bus does not respect subfolder during update process
Wiki Posts Not Green?
Base_url and base_uri
Embed whole Discourse board into Wordpresspage
Backup upload failing
Redirect to discourse from a route in another domain
Redirect to discourse from a route in another domain
Problem with discourse in a subfolder
Install Discourse as subfolder within Wordpress website?
Looking for a developper
Switching forum from subdomain to sub directory
How to install discourse with nginx as proxy on specific path?
All IPs recorded as 127.0.0.1
How to install discourse with nginx as proxy on specific path?
SetupWizard, blank screen, JS Error "`virtual-dom"
Trouble connecting drupal and discourse
National Flags
Failed to Bootstrap - launcher rebuild app
Redirect from one server to another server and keep everything after the URL