<html><head></head><body><div class="ydp1851f5aeyahoo-style-wrap" style="font-family:Helvetica Neue, Helvetica, Arial, sans-serif;font-size:16px;"><div></div>
        <div dir="ltr" data-setdir="false">Hello Ian,</div><div dir="ltr" data-setdir="false"><br></div><div dir="ltr" data-setdir="false">Thank you for your answer. I did what you told me</div><div dir="ltr" data-setdir="false"><br></div><div dir="ltr" data-setdir="false">Now I have on my reverse proxy<br></div><div dir="ltr" data-setdir="false"><div dir="ltr" data-setdir="false">     location / {<br>        proxy_pass              http://10.10.10.10:80;<br>        proxy_redirect          off;<br>        proxy_set_header        Host                    $http_host;<br>        proxy_set_header        X-Real-IP               $remote_addr;<br>#        proxy_set_header        X-Real-IP               $proxy_add_x_forwarded_for;<br>        proxy_set_header        X-Forwarded-For         $proxy_add_x_forwarded_for;<br><div>        proxy_set_header        Referer                 "http://example.org";</div>        #proxy_set_header       Upgrade                 $http_upgrade;<br>        #proxy_pass_header      Set-Cookie;<br>     }<br><div><br></div><div dir="ltr" data-setdir="false">And on the backend server</div><div dir="ltr" data-setdir="false"><div dir="ltr" data-setdir="false"> server {<br clear="none">          listen 80;<br clear="none">          server_name example.org;<br clear="none">          index index.html index.php;<br clear="none">          root /var/www/htdocs/app1;<br clear="none"> <br clear="none">          access_log /var/log/nginx/example.org.access.log;<br clear="none">          error_log /var/log/nginx/example.org.error.log;<br clear="none"> <br clear="none">          location / {<br clear="none">            try_files $uri $uri/ /index.php$is_args$args;<br clear="none"><div>            <span>root /var/www/htdocs/app1;</span></div><br clear="none">          }<br clear="none"> <br clear="none">          location /app2 {<br clear="none">            try_files $uri $uri/ /index.php$is_args$args;<br clear="none"><div>            <span>root /var/www/htdocs/app2;</span></div><br clear="none"><div>          }</div><div dir="ltr" data-setdir="false"><div><div>            location ~ \.php$ {</div><div dir="ltr" data-setdir="false">                <span>try_files $uri    =450;</span><br></div>                fastcgi_pass      unix:/run/php-fpm.app1.sock;<br clear="none">                fastcgi_read_timeout 700;<br clear="none">                fastcgi_split_path_info ^(.+\.php)(/.+)$;<br clear="none">                fastcgi_index     index.php;<br clear="none">                fastcgi_param     SCRIPT_FILENAME  $document_root$fastcgi_script_name;<br clear="none">                include           fastcgi_params;<br clear="none">            }</div><div><br></div></div> }</div><div><br></div><div dir="ltr" data-setdir="false">Access to <span>example.org leads me to app1 so it works as expected.</span></div><div dir="ltr" data-setdir="false"><div><div dir="ltr" data-setdir="false">Access to <span>example.org/app2 doesnt lead me to app2. It seems to me that the following line</span></div><div dir="ltr" data-setdir="false"><span><span>proxy_set_header        Referer                 "http://example.org";</span></span></div><div dir="ltr" data-setdir="false"><span>on the reverse proxy could make a confusion ?</span></div><div dir="ltr" data-setdir="false"><span><br></span></div><div dir="ltr" data-setdir="false"><span>I can see that <span><span>example.org/app2</span></span> still lands on <span><span>/var/www/htdocs/app1</span></span><br></span></div><div dir="ltr" data-setdir="false"><span><br></span></div><div dir="ltr" data-setdir="false"><span>Regards<br></span></div><div dir="ltr" data-setdir="false"><span><br></span></div></div></div></div></div></div><div><br></div>
        
        </div><div id="yahoo_quoted_8841817969" class="yahoo_quoted">
            <div style="font-family:'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:13px;color:#26282a;">
                
                <div>
                    Le mardi 19 juillet 2022 à 06:10:28 UTC+2, Ian Hobson <hobson42@gmail.com> a écrit :
                </div>
                <div><br></div>
                <div><br></div>
                <div><div dir="ltr">Hi Mik,<br clear="none"><br clear="none">I think the problem is that your back end cannot distinguish app1 from <br clear="none">app2. I don't think there is a need for proxy-pass, unless it is to <br clear="none">spread the load.<br clear="none"><br clear="none">I would try the following approach:<br clear="none"><br clear="none">Change the root within location / and location /app2 and<br clear="none">serve static files directly.<br clear="none"><br clear="none">When you pass the .php files, the different roots will  appear in the <br clear="none">$document_root location, so<br clear="none">you can share the php instance.<br clear="none"><br clear="none">It will be MUCH more efficient if you use fast-cgi because it removes a <br clear="none">process create from every php serve.<br clear="none"><br clear="none">Finally, you need to protect against sneaks who try to execute code, by <br clear="none">adding a try_files thus...<br clear="none"><br clear="none">location ~ \.php$ {<br clear="none">    try_files $uri =450;<br clear="none">    include /etc/nginx/fastcgi.conf;<br clear="none">    fastcgi_split_path_info  ^(.+\.php)(/.+)$;<br clear="none">        etc.<br clear="none"><br clear="none">Hope this helps.<br clear="none"><br clear="none">Ian<br clear="none"><br clear="none"><br clear="none">On 18/07/2022 05:08, Mik J via nginx wrote:<br clear="none">> Hello,<br clear="none">> <br clear="none">> I don't manage to make my thing works although it's probably a classic <br clear="none">> for Nginx users.<br clear="none">> <br clear="none">> I have a domain <a shape="rect" href="https://example.org" target="_blank">https://example.org</a><br clear="none">> <br clear="none">> What I want is this<br clear="none">> <a shape="rect" href="https://example.org " target="_blank">https://example.org </a>goes on reverse proxy => server1 (10.10.10.10) to <br clear="none">> the application /var/www/htdocs/app1<br clear="none">> <a shape="rect" href="https://example.org/app2 " target="_blank">https://example.org/app2 </a>goes on reverse proxy => server1 (10.10.10.10) <br clear="none">> to the application /var/www/htdocs/app2<br clear="none">> So in the latter case the user adds /app2 and the flow is redirected to <br clear="none">> the /var/www/htdocs/app2 directory<br clear="none">> <br clear="none">> First the reverse proxy, I wrote this<br clear="none">>      ##<br clear="none">>      # App1<br clear="none">>      ##<br clear="none">>       location / {<br clear="none">>          proxy_pass              <a shape="rect" href="http://10.10.10.10:80;" target="_blank" onclick="return window.theMainWindow.showLinkWarning(this)">http://10.10.10.10:80;</a><br clear="none">>          proxy_redirect          off;<br clear="none">>          proxy_set_header        Host                    $http_host;<br clear="none">>          proxy_set_header        X-Real-IP               $remote_addr;<br clear="none">>          proxy_set_header        X-Forwarded-For         <br clear="none">> $proxy_add_x_forwarded_for;<br clear="none">>          proxy_set_header        Referer                 <br clear="none">> "<a shape="rect" href="http://example.org" target="_blank">http://example.org</a>";<br clear="none">>          #proxy_set_header       Upgrade                 $http_upgrade;<br clear="none">>          #proxy_pass_header      Set-Cookie;<br clear="none">>       }<br clear="none">>      ##<br clear="none">>      # App2<br clear="none">>      ##<br clear="none">>       location /app2 {<br clear="none">>          proxy_pass              <a shape="rect" href="http://10.10.10.10:80;" target="_blank" onclick="return window.theMainWindow.showLinkWarning(this)">http://10.10.10.10:80;</a><br clear="none">>          proxy_redirect          off;<br clear="none">>          proxy_set_header        Host                    $http_host;<br clear="none">>          proxy_set_header        X-Real-IP               $remote_addr;<br clear="none">>          proxy_set_header        X-Forwarded-For         <br clear="none">> $proxy_add_x_forwarded_for;<br clear="none">>          proxy_set_header        Referer                 <br clear="none">> "<a shape="rect" href="http://example.org" target="_blank">http://example.org</a>";<br clear="none">>          #proxy_set_header       Upgrade                 $http_upgrade;<br clear="none">>          #proxy_pass_header      Set-Cookie;<br clear="none">>       }<br clear="none">> <br clear="none">> <br clear="none">> Second the back end server<br clear="none">> server {<br clear="none">>          listen 80;<br clear="none">>          server_name example.org;<br clear="none">>          index index.html index.php;<br clear="none">>          root /var/www/htdocs/app1;<br clear="none">> <br clear="none">>          access_log /var/log/nginx/example.org.access.log;<br clear="none">>          error_log /var/log/nginx/example.org.error.log;<br clear="none">> <br clear="none">>          location / {<br clear="none">>            try_files $uri $uri/ /index.php$is_args$args;<br clear="none">> <br clear="none">>            location ~ \.php$ {<br clear="none">>                root              /var/www/htdocs/app1;<br clear="none">>                fastcgi_pass      unix:/run/php-fpm.app1.sock;<br clear="none">>                fastcgi_read_timeout 700;<br clear="none">>                fastcgi_split_path_info ^(.+\.php)(/.+)$;<br clear="none">>                fastcgi_index     index.php;<br clear="none">>                fastcgi_param     SCRIPT_FILENAME <br clear="none">> $document_root$fastcgi_script_name;<br clear="none">>                include           fastcgi_params;<br clear="none">>            }<br clear="none">>          }<br clear="none">> <br clear="none">>          location /app2 {<br clear="none">>            try_files $uri $uri/ /index.php$is_args$args;<br clear="none">> <br clear="none">>            location ~ \.php$ {<br clear="none">>                root              /var/www/htdocs/app2;<br clear="none">>                fastcgi_pass      unix:/run/php-fpm.app1.sock;<br clear="none">>                fastcgi_read_timeout 700;<br clear="none">>                fastcgi_split_path_info ^(.+\.php)(/.+)$;<br clear="none">>                fastcgi_index     index.php;<br clear="none">>                fastcgi_param     SCRIPT_FILENAME <br clear="none">> $document_root$fastcgi_script_name;<br clear="none">>                include           fastcgi_params;<br clear="none">>            }<br clear="none">>          }<br clear="none">> }<br clear="none">> <br clear="none">> The result I have right now is that I can access app1 with <br clear="none">> <a shape="rect" href="http://example.org, " target="_blank">http://example.org, </a>but i cannot access app2 with <a shape="rect" href="http://example.org/app2" target="_blank">http://example.org/app2</a><br clear="none">> <br clear="none">> Also what is the best practice on the backend server:<br clear="none">> - should I make one single virtual host with two location statements <br clear="none">> like I did or 2 virtual hosts with a fake name like <br clear="none">> internal.app1.example.org and internal.app2.example.org ?<br clear="none">> - can I mutualise the location ~ \.php$ between the two ?<br clear="none">> - Should I copy access_log and error_log in the location /app2 statement ?<br clear="none">> <br clear="none">> By the way, app1 and app2 are the same application/program but sometimes <br clear="none">> I want another instance or test app version 1, app version 2 etc.<br clear="none">> <br clear="none">> What I tend to do in the past is to have<br clear="none">> app1.example.org<br clear="none">> app2.example.org<br clear="none">> The problem is that it makes me use multiple certificates.<br clear="none">> Here I want to group all the applications behind one domain name <br clear="none">> example.org with one certificate and then access different applications <br clear="none">> with example.org/app1, example.org/app2<br clear="none">> <br clear="none">> Thank you<br clear="none">> <br clear="none">> <br clear="none">> <br clear="none">> <br clear="none">> <br clear="none">> <br clear="none">> <br clear="none">> _______________________________________________<br clear="none">> nginx mailing list -- <a shape="rect" ymailto="mailto:nginx@nginx.org" href="mailto:nginx@nginx.org">nginx@nginx.org</a><br clear="none">> To unsubscribe send an email to <a shape="rect" ymailto="mailto:nginx-leave@nginx.org" href="mailto:nginx-leave@nginx.org">nginx-leave@nginx.org</a><br clear="none"><br clear="none">-- <br clear="none">Ian Hobson<br clear="none">Tel (+66) 626 544 695<div class="yqt7011821781" id="yqtfd24883"><br clear="none">_______________________________________________<br clear="none">nginx mailing list -- <a shape="rect" ymailto="mailto:nginx@nginx.org" href="mailto:nginx@nginx.org">nginx@nginx.org</a><br clear="none">To unsubscribe send an email to <a shape="rect" ymailto="mailto:nginx-leave@nginx.org" href="mailto:nginx-leave@nginx.org">nginx-leave@nginx.org</a><br clear="none"></div></div></div>
            </div>
        </div></body></html>