0

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.

G_R0G
  • 1
  • 1
  • What does your current configuration look like? Are you attempting to rewrite URLs inside Nginx before they hit Apache or just proxying Nginx through to Apache? For simplicity and memory reduction, you could consider running only Nginx and having that talk directly to the Prestashop installation. – davidjb Apr 16 '14 at 00:10
  • Thx for your reply. I am on a vps, with ubuntu. Now actually I am proxying nginx to apache and I'm not sure if nginx is the problem. So your suggestion is to use only nginx, but then I won't be able to use the auto-generated .htaccess with the url rewrites. As I mentioned in my first post, I'm new in nginx. Thx for your time. – G_R0G Apr 16 '14 at 10:24

1 Answers1

1

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.

davidjb
  • 8,247
  • 3
  • 32
  • 42
  • Thanks a lot for the useful info. I will try your recommendations and I will keep you informed for the result.Thanx again. – G_R0G Apr 17 '14 at 15:26