-1

I have a Plone4 and Nginx working on the same server (CentOS6). Nginx is working fast but all links on the Plone site received a target="_blank" attribute. All the links are opening in a new window when using Nginx. I open the same Plone site using the Zope webserver or via apache and the problem disapear. I tried different configurations but I cannot get the correct links. How can I solve this?

My current Nginx configuration is:

add_header X-Frame-Options "SAMEORIGIN";
add_header Strict-Transport-Security "max-age=15768000; includeSubDomains";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
#add_header Content-Security-Policy "default-src 'self'; img-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'";
add_header Content-Security-Policy-Report-Only "default-src 'self'; img-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'";

upstream plone {
    server 127.0.0.1:8080;
}

server {
    listen 80;
    server_name mywebsite.com;
    rewrite ^/(.*) http://www.mywebsite.com/$1 permanent;
}

server {
    listen 80;
    server_name www.mywebsite.com;
    access_log /var/log/nginx/mywebsite.com.access.log;
    error_log /var/log/nginx/mywebsite.com.error.log;

    location / {
        #proxy_pass http://plone/VirtualHostBase/http/mywebsite.com:80/mywebsite/VirtualHostRoot/;
        rewrite ^/(.*)$ /VirtualHostBase/http/mywebsite.com:80/mywebsite/VirtualHostRoot/$1 break;
        proxy_pass http://127.0.0.1:8080/;
        proxy_set_header        Host            $host;
        proxy_set_header        X-Real-IP       $remote_addr;
        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}
masegaloeh
  • 17,978
  • 9
  • 56
  • 104
  • nginx does nothing to the page contents. It is something in your Plone that is adding those `target=_blank` attributes to your links. – Tero Kilkanen Mar 15 '15 at 22:56
  • Thanks for your answer Tero, but it only happens when the site is viewed via Nginx. If I open the same site using apache or Plone webserver it works fine. :( – Ricardo Ribeiro Mar 15 '15 at 23:48
  • 3
    I understood that, but the case still IS that nginx does _not_ add any such attributes to the HTML code, unless you enable content modification modules and add specific rules for it to do that. It simply gets HTML code from Plone, and sends it to clients. – Tero Kilkanen Mar 16 '15 at 00:05

1 Answers1

1

It could have somthing to to with your urls. Plone open external urls in new window if enabled.

Check your rewrite rule:

rewrite ^/(.*)$ /VirtualHostBase/http/mywebsite.com:80/mywebsite/VirtualHostRoot/$1 break;

i think it shopuld be:

rewrite ^/(.*)$ /VirtualHostBase/http/www.mywebsite.com:80/mywebsite/VirtualHostRoot/$1 break;
MrTango
  • 126
  • 3
  • I don't know why but in fact Nginx just added the "target" attribute due to the wrong code. I forgot to add the www in the domain and it makes sense. Thank you MrTango you are the best! :))) – Ricardo Ribeiro Mar 21 '15 at 02:58
  • Thats not the nginx, Plone does that. Plone has a Javascript, which looks for URL's different to current. And your nginx config was not complete, so that Plone was thinking, that every link is an external link and add a target="_blank" to it. – MrTango Mar 23 '15 at 07:44