Hosting multiple apps on Nginx Ubuntu 14.04

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












I am having hard time finding a solution. I have a Ubuntu 14.04 machine running NGINX. I have below 2 folders I would like to host.



/var/www/apphost.comp.ill.com/app1/home/index.html
/var/www/apphost.comp.ill.com/app2/index.html



I would like to open app1's index file when I go to "apphost.comp.ill.com/app1" and open app2's index file when I go to "apphost.comp.ill.com/app2".



I believe I need to edit "/etc/nginx/sites-available/apphost.comp.ill.com" to make it happen but I can't seem to figure out how. I tried multiple things, searched online but could not find any solution. Here is how my file looks like currently:



server {
listen 80;
listen [::]:80;

root /var/www/apphost.comp.ill.com/app1/home;
index index.html index.htm home home.html;

# Make site accessible from http://localhost/
server_name apphost.comp.ill.com;

location /
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules



It works for app1 when I go to apphost.comp.ill.com. How can I make it so it works when I go to "apphost.comp.ill.com/app1" and also add app2 to work when I go to "apphost.comp.ill.com/app2".



Please help. Thanks







share|improve this question






















  • I don't know much about Nginx but is the mix of slashes / and backslashes intentional?
    – dreua
    Dec 6 '17 at 22:50










  • Not intentional .. fixed
    – Neo
    Dec 6 '17 at 22:57














up vote
1
down vote

favorite












I am having hard time finding a solution. I have a Ubuntu 14.04 machine running NGINX. I have below 2 folders I would like to host.



/var/www/apphost.comp.ill.com/app1/home/index.html
/var/www/apphost.comp.ill.com/app2/index.html



I would like to open app1's index file when I go to "apphost.comp.ill.com/app1" and open app2's index file when I go to "apphost.comp.ill.com/app2".



I believe I need to edit "/etc/nginx/sites-available/apphost.comp.ill.com" to make it happen but I can't seem to figure out how. I tried multiple things, searched online but could not find any solution. Here is how my file looks like currently:



server {
listen 80;
listen [::]:80;

root /var/www/apphost.comp.ill.com/app1/home;
index index.html index.htm home home.html;

# Make site accessible from http://localhost/
server_name apphost.comp.ill.com;

location /
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules



It works for app1 when I go to apphost.comp.ill.com. How can I make it so it works when I go to "apphost.comp.ill.com/app1" and also add app2 to work when I go to "apphost.comp.ill.com/app2".



Please help. Thanks







share|improve this question






















  • I don't know much about Nginx but is the mix of slashes / and backslashes intentional?
    – dreua
    Dec 6 '17 at 22:50










  • Not intentional .. fixed
    – Neo
    Dec 6 '17 at 22:57












up vote
1
down vote

favorite









up vote
1
down vote

favorite











I am having hard time finding a solution. I have a Ubuntu 14.04 machine running NGINX. I have below 2 folders I would like to host.



/var/www/apphost.comp.ill.com/app1/home/index.html
/var/www/apphost.comp.ill.com/app2/index.html



I would like to open app1's index file when I go to "apphost.comp.ill.com/app1" and open app2's index file when I go to "apphost.comp.ill.com/app2".



I believe I need to edit "/etc/nginx/sites-available/apphost.comp.ill.com" to make it happen but I can't seem to figure out how. I tried multiple things, searched online but could not find any solution. Here is how my file looks like currently:



server {
listen 80;
listen [::]:80;

root /var/www/apphost.comp.ill.com/app1/home;
index index.html index.htm home home.html;

# Make site accessible from http://localhost/
server_name apphost.comp.ill.com;

location /
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules



It works for app1 when I go to apphost.comp.ill.com. How can I make it so it works when I go to "apphost.comp.ill.com/app1" and also add app2 to work when I go to "apphost.comp.ill.com/app2".



Please help. Thanks







share|improve this question














I am having hard time finding a solution. I have a Ubuntu 14.04 machine running NGINX. I have below 2 folders I would like to host.



/var/www/apphost.comp.ill.com/app1/home/index.html
/var/www/apphost.comp.ill.com/app2/index.html



I would like to open app1's index file when I go to "apphost.comp.ill.com/app1" and open app2's index file when I go to "apphost.comp.ill.com/app2".



I believe I need to edit "/etc/nginx/sites-available/apphost.comp.ill.com" to make it happen but I can't seem to figure out how. I tried multiple things, searched online but could not find any solution. Here is how my file looks like currently:



server {
listen 80;
listen [::]:80;

root /var/www/apphost.comp.ill.com/app1/home;
index index.html index.htm home home.html;

# Make site accessible from http://localhost/
server_name apphost.comp.ill.com;

location /
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules



It works for app1 when I go to apphost.comp.ill.com. How can I make it so it works when I go to "apphost.comp.ill.com/app1" and also add app2 to work when I go to "apphost.comp.ill.com/app2".



Please help. Thanks









share|improve this question













share|improve this question




share|improve this question








edited Dec 6 '17 at 22:57

























asked Dec 6 '17 at 21:15









Neo

134




134











  • I don't know much about Nginx but is the mix of slashes / and backslashes intentional?
    – dreua
    Dec 6 '17 at 22:50










  • Not intentional .. fixed
    – Neo
    Dec 6 '17 at 22:57
















  • I don't know much about Nginx but is the mix of slashes / and backslashes intentional?
    – dreua
    Dec 6 '17 at 22:50










  • Not intentional .. fixed
    – Neo
    Dec 6 '17 at 22:57















I don't know much about Nginx but is the mix of slashes / and backslashes intentional?
– dreua
Dec 6 '17 at 22:50




I don't know much about Nginx but is the mix of slashes / and backslashes intentional?
– dreua
Dec 6 '17 at 22:50












Not intentional .. fixed
– Neo
Dec 6 '17 at 22:57




Not intentional .. fixed
– Neo
Dec 6 '17 at 22:57










2 Answers
2






active

oldest

votes

















up vote
0
down vote



accepted










I tried this and it works:



server 
listen 80;
listen [::]:80;

index index.html index.htm home home.html;

# Make site accessible from http://localhost/
server_name apphost.comp.ill.com;

location /app1
# we need to use alias here to strip the "app1" from
# the requested path
alias /var/www/apphost.comp.ill.com/app1/home;

# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules

location /app2
# we don't need an alias here because app2 matches the
# directory structure
root /var/www/apphost.comp.ill.com/;

# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules




I would recommend /app1 and /app2 without a leading slash because in my test browsing to .../app1 didn't work otherwise.



Documentation of the alias command: http://nginx.org/en/docs/http/ngx_http_core_module.html#alias






share|improve this answer




















  • That worked ... thanks
    – Neo
    Dec 13 '17 at 23:41

















up vote
0
down vote













Edit: This answer is wrong, because the part after "location" will be appended to the document root. (i.e. nginx tries to open the file /var/www/apphost.comp.ill.com/app1/home/app1/index.html) I should not have posted it without trying first, sorry.



Have you tried:



server 
listen 80;
listen [::]:80;

index index.html index.htm home home.html;

# Make site accessible from http://localhost/
server_name apphost.comp.ill.com;

location /app1/
root /var/www/apphost.comp.ill.com/app1/home;
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules

location /app2/
root /var/www/apphost.comp.ill.com/app2;
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules







share|improve this answer






















  • That did not work
    – Neo
    Dec 7 '17 at 20:40










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f409315%2fhosting-multiple-apps-on-nginx-ubuntu-14-04%23new-answer', 'question_page');

);

Post as a guest






























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote



accepted










I tried this and it works:



server 
listen 80;
listen [::]:80;

index index.html index.htm home home.html;

# Make site accessible from http://localhost/
server_name apphost.comp.ill.com;

location /app1
# we need to use alias here to strip the "app1" from
# the requested path
alias /var/www/apphost.comp.ill.com/app1/home;

# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules

location /app2
# we don't need an alias here because app2 matches the
# directory structure
root /var/www/apphost.comp.ill.com/;

# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules




I would recommend /app1 and /app2 without a leading slash because in my test browsing to .../app1 didn't work otherwise.



Documentation of the alias command: http://nginx.org/en/docs/http/ngx_http_core_module.html#alias






share|improve this answer




















  • That worked ... thanks
    – Neo
    Dec 13 '17 at 23:41














up vote
0
down vote



accepted










I tried this and it works:



server 
listen 80;
listen [::]:80;

index index.html index.htm home home.html;

# Make site accessible from http://localhost/
server_name apphost.comp.ill.com;

location /app1
# we need to use alias here to strip the "app1" from
# the requested path
alias /var/www/apphost.comp.ill.com/app1/home;

# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules

location /app2
# we don't need an alias here because app2 matches the
# directory structure
root /var/www/apphost.comp.ill.com/;

# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules




I would recommend /app1 and /app2 without a leading slash because in my test browsing to .../app1 didn't work otherwise.



Documentation of the alias command: http://nginx.org/en/docs/http/ngx_http_core_module.html#alias






share|improve this answer




















  • That worked ... thanks
    – Neo
    Dec 13 '17 at 23:41












up vote
0
down vote



accepted







up vote
0
down vote



accepted






I tried this and it works:



server 
listen 80;
listen [::]:80;

index index.html index.htm home home.html;

# Make site accessible from http://localhost/
server_name apphost.comp.ill.com;

location /app1
# we need to use alias here to strip the "app1" from
# the requested path
alias /var/www/apphost.comp.ill.com/app1/home;

# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules

location /app2
# we don't need an alias here because app2 matches the
# directory structure
root /var/www/apphost.comp.ill.com/;

# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules




I would recommend /app1 and /app2 without a leading slash because in my test browsing to .../app1 didn't work otherwise.



Documentation of the alias command: http://nginx.org/en/docs/http/ngx_http_core_module.html#alias






share|improve this answer












I tried this and it works:



server 
listen 80;
listen [::]:80;

index index.html index.htm home home.html;

# Make site accessible from http://localhost/
server_name apphost.comp.ill.com;

location /app1
# we need to use alias here to strip the "app1" from
# the requested path
alias /var/www/apphost.comp.ill.com/app1/home;

# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules

location /app2
# we don't need an alias here because app2 matches the
# directory structure
root /var/www/apphost.comp.ill.com/;

# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules




I would recommend /app1 and /app2 without a leading slash because in my test browsing to .../app1 didn't work otherwise.



Documentation of the alias command: http://nginx.org/en/docs/http/ngx_http_core_module.html#alias







share|improve this answer












share|improve this answer



share|improve this answer










answered Dec 9 '17 at 18:19









dreua

1857




1857











  • That worked ... thanks
    – Neo
    Dec 13 '17 at 23:41
















  • That worked ... thanks
    – Neo
    Dec 13 '17 at 23:41















That worked ... thanks
– Neo
Dec 13 '17 at 23:41




That worked ... thanks
– Neo
Dec 13 '17 at 23:41












up vote
0
down vote













Edit: This answer is wrong, because the part after "location" will be appended to the document root. (i.e. nginx tries to open the file /var/www/apphost.comp.ill.com/app1/home/app1/index.html) I should not have posted it without trying first, sorry.



Have you tried:



server 
listen 80;
listen [::]:80;

index index.html index.htm home home.html;

# Make site accessible from http://localhost/
server_name apphost.comp.ill.com;

location /app1/
root /var/www/apphost.comp.ill.com/app1/home;
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules

location /app2/
root /var/www/apphost.comp.ill.com/app2;
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules







share|improve this answer






















  • That did not work
    – Neo
    Dec 7 '17 at 20:40














up vote
0
down vote













Edit: This answer is wrong, because the part after "location" will be appended to the document root. (i.e. nginx tries to open the file /var/www/apphost.comp.ill.com/app1/home/app1/index.html) I should not have posted it without trying first, sorry.



Have you tried:



server 
listen 80;
listen [::]:80;

index index.html index.htm home home.html;

# Make site accessible from http://localhost/
server_name apphost.comp.ill.com;

location /app1/
root /var/www/apphost.comp.ill.com/app1/home;
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules

location /app2/
root /var/www/apphost.comp.ill.com/app2;
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules







share|improve this answer






















  • That did not work
    – Neo
    Dec 7 '17 at 20:40












up vote
0
down vote










up vote
0
down vote









Edit: This answer is wrong, because the part after "location" will be appended to the document root. (i.e. nginx tries to open the file /var/www/apphost.comp.ill.com/app1/home/app1/index.html) I should not have posted it without trying first, sorry.



Have you tried:



server 
listen 80;
listen [::]:80;

index index.html index.htm home home.html;

# Make site accessible from http://localhost/
server_name apphost.comp.ill.com;

location /app1/
root /var/www/apphost.comp.ill.com/app1/home;
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules

location /app2/
root /var/www/apphost.comp.ill.com/app2;
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules







share|improve this answer














Edit: This answer is wrong, because the part after "location" will be appended to the document root. (i.e. nginx tries to open the file /var/www/apphost.comp.ill.com/app1/home/app1/index.html) I should not have posted it without trying first, sorry.



Have you tried:



server 
listen 80;
listen [::]:80;

index index.html index.htm home home.html;

# Make site accessible from http://localhost/
server_name apphost.comp.ill.com;

location /app1/
root /var/www/apphost.comp.ill.com/app1/home;
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules

location /app2/
root /var/www/apphost.comp.ill.com/app2;
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules








share|improve this answer














share|improve this answer



share|improve this answer








edited Dec 9 '17 at 18:08

























answered Dec 6 '17 at 23:36









dreua

1857




1857











  • That did not work
    – Neo
    Dec 7 '17 at 20:40
















  • That did not work
    – Neo
    Dec 7 '17 at 20:40















That did not work
– Neo
Dec 7 '17 at 20:40




That did not work
– Neo
Dec 7 '17 at 20:40

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f409315%2fhosting-multiple-apps-on-nginx-ubuntu-14-04%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay