Correct way to add rewrite rules to Nginx


(Peter Backx) #1

I’m currently migrating a discussion board to Discourse. I’m still learning about how Discourse is distributed and set up, but I’ve got the data imported and everything configured.

After importing all the topics, I now have a long list of mappings from the old topic id to the new Discourse topic id.

I’d like to put all of these into rewrite rules and add them to the Nginx server.

My question: what is the best way to do this?

I don’t think it’s a good idea to just put them in the /etc/nginx/conf.d/discourse.conf as that may cause issues when upgrading Discourse in the future. Or won’t it?

Can I put them in a separate conf? Will that file survive when the server restarts and/or updates are made to the Docker container? (or is that not even an issue and should I stop worrying :tropical_drink: )


(Sam Saffron) #2

Add a template or a hook and do a replace rule. see the ssl template in the templates directory for an example.


(Jeff Atwood) #3

No I think he means a list of old ID mapping to new IDs. @neil didn’t you add support for this kind of lookup table somewhere?


(Sam Saffron) #4

Yeah, for that there is this howto


(Peter Backx) #5

Thanks for the pointer.

Since I’m a Ruby novice and I barely know enough to be dangerous, I’d prefer to keep this separate. It will also be easier (I hope) to update on the fly, if it turns out I forgot to map some rules once I have flipped the switch and turned on the Discourse forum.

I’m going to try to use the Nginx map module first and see how that goes:


(Neil Lalonde) #6

It’s definitely a preference. Yesterday I was able to add one rule to one site’s permalinks table because they wanted a certain redirect from their old forums to their new forums that we host. In our environment, this was much easier than updating haproxy config. I don’t want to fill our config files with countless arbitrary redirects from all our customers. It would be insane for us, but maybe not for you.


(system) #7