<html><head></head><body><div class="ydp8206f94dyahoo-style-wrap" style="font-family:Helvetica Neue, Helvetica, Arial, sans-serif;font-size:16px;"><div></div>
        <div dir="ltr" data-setdir="false">Hello everyone,</div><div dir="ltr" data-setdir="false"><br></div><div dir="ltr" data-setdir="false">I'm still trying to solve my implementation.</div><div dir="ltr" data-setdir="false"><br></div><div dir="ltr" data-setdir="false">When I access to example.org, I was to use /var/www/htdocs/app1 and it works.<br></div><div><br></div><div dir="ltr" data-setdir="false"><span>When I access to example.org/app2, I was to use /var/www/htdocs/app2 and it doesn't really work.</span></div><div dir="ltr" data-setdir="false"><br></div><div dir="ltr" data-setdir="false"><div dir="ltr" data-setdir="false">        location / {<br>          try_files $uri $uri/ /index.php$is_args$args;<br>        root /var/www/htdocs/app1;<br><br>          location ~ \.php$ {<br>              root /var/www/htdocs/app1;<br>              try_files $uri    =450;<br>              fastcgi_pass      unix:/run/php-fpm.sock;<br>              fastcgi_read_timeout 700;<br>              fastcgi_split_path_info ^(.+\.php)(/.+)$;<br>              fastcgi_index     index.php;<br>              fastcgi_param     SCRIPT_FILENAME $document_root$fastcgi_script_name;<br>              include           fastcgi_params;<br>          }<br><br>        }<br><br>        location /app2 {<br>          #root /var/www/htdocs/app2;<br>          alias /var/www/htdocs/app2;<br>          try_files $uri $uri/ /index.php$is_args$args;<br><br>          location ~ \.php$ {<br>              root              /var/www/htdocs/app2;<br>              #alias /var/www/htdocs/app2;<br>              try_files $uri   =450;<br><div>              fastcgi_pass   unix:/run/ <span>php-fpm.sock;</span></div>#              fastcgi_read_timeout 700;<br>              fastcgi_split_path_info ^(.+\.php)(/.+)$;<br>              fastcgi_index  index.php;<br>              fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;<br>              include        fastcgi_params;<br>          }<br>        }<br><br></div><div dir="ltr" data-setdir="false">I have created an index.html file in <span>/var/www/htdocs/app2, when I access it with example.org/app2/index.html I can see the html text.</span></div><div dir="ltr" data-setdir="false"><br></div><div dir="ltr" data-setdir="false">Problem<br></div><div dir="ltr" data-setdir="false">My application has to be accessed with index.php so when I type <span><span>example.org/app2/index.php, Nginx should process <span>/var/www/htdocs/app2/index.php</span></span></span></div><div dir="ltr" data-setdir="false">The problem is that I receive a code 404. I don't receive a code 450.</div><div dir="ltr" data-setdir="false">It looks like the condition location /app2 matches but <span>location ~ \.php$ inside doesn't match</span></div><div dir="ltr" data-setdir="false"><br></div><div dir="ltr" data-setdir="false"><br></div><div dir="ltr" data-setdir="false">Then I tried to replace alias by root just after location /app2 and I do get this error code 450. the <span>location ~ \.php$ seems to match but the php code is not being processed.</span></div><div dir="ltr" data-setdir="false"><br></div><div dir="ltr" data-setdir="false">Does anyone has a idea ?<br></div></div>
        
        </div><div id="yahoo_quoted_9052505995" class="yahoo_quoted">
            <div style="font-family:'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:13px;color:#26282a;">
                
                <div>
                    Le mardi 19 juillet 2022 à 16:32:05 UTC+2, Mik J via nginx <nginx@nginx.org> a écrit :
                </div>
                <div><br></div>
                <div><br></div>
                <div><div id="yiv9969252447"><div><div style="font-family:Helvetica Neue, Helvetica, Arial, sans-serif;font-size:16px;" class="yiv9969252447ydp1851f5aeyahoo-style-wrap"><div></div>
        <div dir="ltr">Hello Ian,</div><div dir="ltr"><br clear="none"></div><div dir="ltr">Thank you for your answer. I did what you told me</div><div dir="ltr"><br clear="none"></div><div dir="ltr">Now I have on my reverse proxy<br clear="none"></div><div dir="ltr"><div dir="ltr">     location / {<br clear="none">        proxy_pass              http://10.10.10.10:80;<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-Real-IP               $proxy_add_x_forwarded_for;<br clear="none">        proxy_set_header        X-Forwarded-For         $proxy_add_x_forwarded_for;<br clear="none"><div>        proxy_set_header        Referer                 "http://example.org";</div>        #proxy_set_header       Upgrade                 $http_upgrade;<br clear="none">        #proxy_pass_header      Set-Cookie;<br clear="none">     }<br clear="none"><div><br clear="none"></div><div dir="ltr">And on the backend server</div><div dir="ltr"><div dir="ltr"> 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"><div><div>            location ~ \.php$ {</div><div dir="ltr">                <span>try_files $uri    =450;</span><br clear="none"></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 clear="none"></div></div> }</div><div><br clear="none"></div><div dir="ltr">Access to <span>example.org leads me to app1 so it works as expected.</span></div><div dir="ltr"><div><div dir="ltr">Access to <span>example.org/app2 doesnt lead me to app2. It seems to me that the following line</span></div><div dir="ltr"><span><span>proxy_set_header        Referer                 "http://example.org";</span></span></div><div dir="ltr"><span>on the reverse proxy could make a confusion ?</span></div><div dir="ltr"><span><br clear="none"></span></div><div dir="ltr"><span>I can see that <span><span>example.org/app2</span></span> still lands on <span><span>/var/www/htdocs/app1</span></span><br clear="none"></span></div><div dir="ltr"><span><br clear="none"></span></div><div dir="ltr"><span>Regards<br clear="none"></span></div><div dir="ltr"><span><br clear="none"></span></div></div></div></div></div></div><div><br clear="none"></div>
        
        </div><div id="yiv9969252447yqt51031" class="yiv9969252447yqt7783321251"><div id="yiv9969252447yahoo_quoted_8841817969" class="yiv9969252447yahoo_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 clear="none"></div>
                <div><br clear="none"></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 rel="nofollow noopener noreferrer" shape="rect" target="_blank" href="https://example.org">https://example.org</a><br clear="none">> <br clear="none">> What I want is this<br clear="none">> <a rel="nofollow noopener noreferrer" shape="rect" target="_blank" href="https://example.org ">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 rel="nofollow noopener noreferrer" shape="rect" target="_blank" href="https://example.org/app2 ">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 rel="nofollow noopener noreferrer" shape="rect" target="_blank" onclick="return window.theMainWindow.showLinkWarning(this)" href="http://10.10.10.10:80;">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 rel="nofollow noopener noreferrer" shape="rect" target="_blank" href="http://example.org">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 rel="nofollow noopener noreferrer" shape="rect" target="_blank" onclick="return window.theMainWindow.showLinkWarning(this)" href="http://10.10.10.10:80;">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 rel="nofollow noopener noreferrer" shape="rect" target="_blank" href="http://example.org">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 rel="nofollow noopener noreferrer" shape="rect" target="_blank" href="http://example.org, ">http://example.org, </a>but i cannot access app2 with <a rel="nofollow noopener noreferrer" shape="rect" target="_blank" href="http://example.org/app2">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 rel="nofollow noopener noreferrer" shape="rect" ymailto="mailto:nginx@nginx.org" target="_blank" href="mailto:nginx@nginx.org">nginx@nginx.org</a><br clear="none">> To unsubscribe send an email to <a rel="nofollow noopener noreferrer" shape="rect" ymailto="mailto:nginx-leave@nginx.org" target="_blank" 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 id="yiv9969252447yqtfd24883" class="yiv9969252447yqt7011821781"><br clear="none">_______________________________________________<br clear="none">nginx mailing list -- <a rel="nofollow noopener noreferrer" shape="rect" ymailto="mailto:nginx@nginx.org" target="_blank" href="mailto:nginx@nginx.org">nginx@nginx.org</a><br clear="none">To unsubscribe send an email to <a rel="nofollow noopener noreferrer" shape="rect" ymailto="mailto:nginx-leave@nginx.org" target="_blank" href="mailto:nginx-leave@nginx.org">nginx-leave@nginx.org</a><br clear="none"></div></div></div>
            </div>
        </div></div></div></div><div class="yqt7783321251" id="yqt20331">_______________________________________________<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></body></html>