We are using discourse as a subdirectory. It works but had taken a lot of trial and error by our hosting expert.
I do not know the details. I know that he added reverse proxies and proxy passes to our nginx but that’s all I can say. We followed to documentation that pfaffman linked but even then, depending on your stack there’s a lot of customization to do.
I would not recommend unless you have resources to invest into it.