P
P
Pavel Hudinsky2014-09-05 09:51:16
PHP
Pavel Hudinsky, 2014-09-05 09:51:16

How to correctly set up multiple projects with the same domain-name but different "suffixes" (nginx)?

There is a server with nginx on it. There are about 10 projects on the server (all on symfony2), all of them should be accessible by the same domain name, but with different "suffixes", for example:
domain name - example.com
address of the first project - example.com/project1/
address of the second project - example.com/project2/
...
I myself configured nginx to work this way, but one big inconvenient situation pops up:
now in all views and templates you have to add this suffix when generating, like /project1/bla/bla/bla. In order for everything to be in Feng Shui, you have to throw in the value of this suffix in the parameters and stick it in all places, and if the css contains links to resources, then this is generally terrible.
Is there a way in nginx to rewrite the internal variable for each project so that /bla/bla/bla links by default lead to example.com/project{number}/bla/bla/bla ? Or maybe someone can suggest a better solution?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Solomonov, 2014-09-05
@Wendor

Look, for example, in exmple.com/project1/main.css you have a link to the image /bla/bla/bla.jpg. This means that you have a link exmple.com/bla/bla/bla.jpg. Nginx will not determine in any way which project it belongs to. So, the task set by means of nginx cannot be implemented. To solve the problem, you can only use relative links like bla/bla/bla.jpg.
Or you can add some get parameter /bla/bla/bla.jpg?project=project1 to the links, and in nginx, when a parameter is found, do root /project1, but this is still hemorrhoids.
If you want nginx to rewrite links before giving the page to the client (to replace /bla/bla/bla.jpg with /project1/bla/bla/bla.jpg), then you can also forget about this. It will be necessary to train the web server in ccs, js and html ... to understand the page code and replace it automatically. It's practically unrealistic.
upd: Crazy idea... upon request, parse the referer line with nginx for ^/project1, and if successful, append to do a rewrite to this same project1 :-)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question