Reputation: 1
I'm trying to figure out how to re-write urls using nginx in front of an apache. I am new to a set up like that and after an extensive research I couldn't figure it out.
I am trying to enable seo friendly urls in a prestashop 1.6.0.6 installation without any luck. The truth is that this is really straightforward when using only an apache as a web server.
I would appreciate it if someone could help me on this.
Upvotes: 0
Views: 770
Reputation: 8727
Whether this will work depends on how your Apache server is configured to accept the URLs. If Apache is configured, as you mentioned with a .htacess
file, to serve at the root of the host name, then rewriting may not be required. An example Nginx server block like this:
server {
server_name nginx.example.org;
location / {
proxy_set_header Host $host;
proxy_pass http://apache.example.org:80 break;
}
}
will pass the exact host and path being accessed from Nginx through to Apache without any changes. The server_name
and proxy_pass
directives will need to be changed for your local configuration, however. In this case, because of the use of the location / {}
, all paths are accepted and proxied.
As long as the backend Apache is configured correctly and accessible from Nginx, this should work. The best test would be to ensure that you can access resources on Apache directly first, especially those with the SEO-friendly URLs, which would indicate the .htaccess
file is in working and effect. Then configure Nginx in front as per the above.
As for potentially using only Nginx, you could port the rules from the .htaccess
over into rewrite
directives within Nginx configuration. In my experience, the rules are very similar in functionality and structure:
Apache: RewriteRule ^/(.*\.jpg)$ /images/$1 [L]
Nginx: rewrite ^/(.*\.jpg)$ /images/$1 last;
More information is at the Nginx wiki.
Upvotes: 1