<html><head></head><body><div class="yahoo-style-wrap" style="font-family:Helvetica Neue, Helvetica, Arial, sans-serif;font-size:16px;"><div dir="ltr" data-setdir="false">Hello,</div><div dir="ltr" data-setdir="false"><br></div><div dir="ltr" data-setdir="false">I don't manage to make my thing works although it's probably a classic for Nginx users.</div><div dir="ltr" data-setdir="false"><br></div><div dir="ltr" data-setdir="false">I have a domain https://example.org</div><div><br></div><div>What I want is this</div><div dir="ltr" data-setdir="false"><span>https://example.org</span> goes on reverse proxy => server1 (10.10.10.10) to the application /var/www/htdocs/app1</div><div dir="ltr" data-setdir="false"><span><span>https://example.org/app2</span> goes on reverse proxy => server1 (10.10.10.10) to the application /var/www/htdocs/app2</span> <br></div><div dir="ltr" data-setdir="false">So in the latter case the user adds /app2 and the flow is redirected to the <span><span>/var/www/htdocs/app2 directory</span></span></div><div dir="ltr" data-setdir="false"><br></div><div dir="ltr" data-setdir="false">First the reverse proxy, I wrote this</div><div dir="ltr" data-setdir="false"><div dir="ltr" data-setdir="false"> ##<br><div> # App1</div> ##<br> location / {<br><div> proxy_pass http://<span>10.10.10.10</span>:80;</div> proxy_redirect off;<br> proxy_set_header Host $http_host;<br> proxy_set_header X-Real-IP $remote_addr;<br> proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;<br><div> proxy_set_header Referer "http://<span><span><span>example.org</span></span></span>";</div> #proxy_set_header Upgrade $http_upgrade;<br> #proxy_pass_header Set-Cookie;<br> }<br> ##<br><div> # App2</div> ##<br> location /app2 {<br><div> proxy_pass http://<span>10.10.10.10</span>:80;</div> proxy_redirect off;<br> proxy_set_header Host $http_host;<br> proxy_set_header X-Real-IP $remote_addr;<br> proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;<br><div> proxy_set_header Referer "http://<span><span><span>example.org</span></span></span>";</div> #proxy_set_header Upgrade $http_upgrade;<br> #proxy_pass_header Set-Cookie;<br> }<br><br></div><div><br></div><div dir="ltr" data-setdir="false">Second the back end server</div><div dir="ltr" data-setdir="false"><div dir="ltr" data-setdir="false">server {<br> listen 80;<br><div> server_name <span><span><span><span>example.org</span></span></span></span>;</div> index index.html index.php;<br> root /var/www/htdocs/app1;<br><br><div> access_log /var/log/nginx/<span><span><span><span><span>example.org</span></span></span></span></span>.access.log;</div><div> error_log /var/log/nginx/<span><span><span><span><span>example.org</span></span></span></span></span>.error.log;</div><div><br></div><div dir="ltr" data-setdir="false"><div dir="ltr" data-setdir="false"> location / {<br><div> try_files $uri $uri/ /index.php$is_args$args;</div><div><br></div><div> location ~ \.php$ {<br><div> root /var/www/htdocs/app1;<br></div><div> fastcgi_pass unix:/run/php-fpm.app1.sock;</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><div><br></div><div dir="ltr" data-setdir="false"><div dir="ltr" data-setdir="false"> <div> location /app2 {<br><div> try_files $uri $uri/ /index.php$is_args$args;</div><div><br></div> location ~ \.php$ {<br><div> root /var/www/htdocs/app2;<br></div><div> fastcgi_pass unix:/run/php-fpm.app1.sock;</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> }</div><div>}</div><div><br></div><div dir="ltr" data-setdir="false">The result I have right now is that I can access app1 with <span>http://<span><span><span>example.org</span></span></span></span>, but i cannot access app2 with <span>http://<span><span><span>example.org</span></span></span></span>/app2</div><div dir="ltr" data-setdir="false"><br></div><div dir="ltr" data-setdir="false">Also what is the best practice on the backend server:</div><div dir="ltr" data-setdir="false">- should I make one single virtual host with two location statements like I did or 2 virtual hosts with a fake name like internal.app1.example.org and <span>internal.app2.example.org ?<br></span></div><div dir="ltr" data-setdir="false">- can I mutualise the <span>location ~ \.php$ between the two ?<br></span></div><div dir="ltr" data-setdir="false">- Should I copy access_log and error_log in the location /app2 statement ?<br></div></div><div><br></div><div dir="ltr" data-setdir="false">By the way, app1 and app2 are the same application/program but sometimes I want another instance or test app version 1, app version 2 etc.</div><div dir="ltr" data-setdir="false"><br></div><div dir="ltr" data-setdir="false">What I tend to do in the past is to have</div><div dir="ltr" data-setdir="false">app1.example.org</div><div dir="ltr" data-setdir="false">app2.example.org</div><div dir="ltr" data-setdir="false">The problem is that it makes me use multiple certificates.</div><div dir="ltr" data-setdir="false">Here I want to group all the applications behind one domain name example.org with one certificate and then access different applications with example.org/app1, <span>example.org/app2</span></div><div dir="ltr" data-setdir="false"><br></div><div dir="ltr" data-setdir="false">Thank you<br></div></div><div><br></div></div></div></div></div><div dir="ltr" data-setdir="false"><div><br></div></div></div></div><div dir="ltr" data-setdir="false"><br></div><div><br></div><div dir="ltr" data-setdir="false"><br></div><div dir="ltr" data-setdir="false"><br></div></div></body></html>