How to configure nginx in a container to access a built vue app in a custom path location. NGINX returns 404












1














I have a docker swarm setup with a parent nginx container that is open on 443 and 80 that proxies to a backend node app and a built vue cli application in a nginx container. Everything works great on that end. I want to add a 2nd vue-cli app also built with a nginx container with a path.



My parent nginx location is a simple proxy_pass



...
location /admin { # this location does not proxy
proxy_pass http://admin:80;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location /{ # this location works
proxy_pass http://ui:80;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
...


I am able to exec into the parent nginx service which is public facing and curl http://admin:80 and the html displays. I know the parent nginx service has access to the vue nginx service.



When I go to https://myurl.com/admin I get the standard 404 Not Found



My Dockerfile for the parent nginx



FROM nginx
COPY nginx.conf /etc/nginx/nginx.conf
COPY cert.crt /etc/ssl/certs/mywebsite.com.crt
COPY kk.key /etc/ssl/certs/mywebsite.com.key


My Dockerfile for the vue apps



FROM nginx
COPY dist/ /usr/share/nginx/html


My docker swarm services are all in a common overlay network on a single node.



ID                  NAME                MODE                REPLICAS            IMAGE                                                                         PORTS
hbd8mpwbxisw admin replicated 2/2 registry.gitlab.com/mygitlabsite/adminui:2
fmgx9qzlai9t nginx replicated 2/2 registry.gitlab.com/mygitlabsite/nginx-config:4 *:80->80/tcp, *:443->443/tcp
q0qrhbthzdbu ui replicated 2/2 registry.gitlab.com/mygitlabsite/ui:2
bmjlip3k0iph web replicated 2/2 mynodeapp:1


My admin Vue-CLI app I added to my vue.config.js baseUrl: '/admin',
as well as in my router base: process.env.BASE_URL,



Any help appreciated










share|improve this question
























  • Your docker image is called registry.gitlab.com/mygitlabsite/adminui:2 (adminui instead of admin) - typo somewhere else?
    – Bennett Dams
    Nov 20 at 19:39










  • The docker swarm dns service is based on the name. I am able to curl the admin:80 and get a response.
    – Varcorb
    Nov 20 at 19:40
















1














I have a docker swarm setup with a parent nginx container that is open on 443 and 80 that proxies to a backend node app and a built vue cli application in a nginx container. Everything works great on that end. I want to add a 2nd vue-cli app also built with a nginx container with a path.



My parent nginx location is a simple proxy_pass



...
location /admin { # this location does not proxy
proxy_pass http://admin:80;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location /{ # this location works
proxy_pass http://ui:80;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
...


I am able to exec into the parent nginx service which is public facing and curl http://admin:80 and the html displays. I know the parent nginx service has access to the vue nginx service.



When I go to https://myurl.com/admin I get the standard 404 Not Found



My Dockerfile for the parent nginx



FROM nginx
COPY nginx.conf /etc/nginx/nginx.conf
COPY cert.crt /etc/ssl/certs/mywebsite.com.crt
COPY kk.key /etc/ssl/certs/mywebsite.com.key


My Dockerfile for the vue apps



FROM nginx
COPY dist/ /usr/share/nginx/html


My docker swarm services are all in a common overlay network on a single node.



ID                  NAME                MODE                REPLICAS            IMAGE                                                                         PORTS
hbd8mpwbxisw admin replicated 2/2 registry.gitlab.com/mygitlabsite/adminui:2
fmgx9qzlai9t nginx replicated 2/2 registry.gitlab.com/mygitlabsite/nginx-config:4 *:80->80/tcp, *:443->443/tcp
q0qrhbthzdbu ui replicated 2/2 registry.gitlab.com/mygitlabsite/ui:2
bmjlip3k0iph web replicated 2/2 mynodeapp:1


My admin Vue-CLI app I added to my vue.config.js baseUrl: '/admin',
as well as in my router base: process.env.BASE_URL,



Any help appreciated










share|improve this question
























  • Your docker image is called registry.gitlab.com/mygitlabsite/adminui:2 (adminui instead of admin) - typo somewhere else?
    – Bennett Dams
    Nov 20 at 19:39










  • The docker swarm dns service is based on the name. I am able to curl the admin:80 and get a response.
    – Varcorb
    Nov 20 at 19:40














1












1








1


0





I have a docker swarm setup with a parent nginx container that is open on 443 and 80 that proxies to a backend node app and a built vue cli application in a nginx container. Everything works great on that end. I want to add a 2nd vue-cli app also built with a nginx container with a path.



My parent nginx location is a simple proxy_pass



...
location /admin { # this location does not proxy
proxy_pass http://admin:80;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location /{ # this location works
proxy_pass http://ui:80;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
...


I am able to exec into the parent nginx service which is public facing and curl http://admin:80 and the html displays. I know the parent nginx service has access to the vue nginx service.



When I go to https://myurl.com/admin I get the standard 404 Not Found



My Dockerfile for the parent nginx



FROM nginx
COPY nginx.conf /etc/nginx/nginx.conf
COPY cert.crt /etc/ssl/certs/mywebsite.com.crt
COPY kk.key /etc/ssl/certs/mywebsite.com.key


My Dockerfile for the vue apps



FROM nginx
COPY dist/ /usr/share/nginx/html


My docker swarm services are all in a common overlay network on a single node.



ID                  NAME                MODE                REPLICAS            IMAGE                                                                         PORTS
hbd8mpwbxisw admin replicated 2/2 registry.gitlab.com/mygitlabsite/adminui:2
fmgx9qzlai9t nginx replicated 2/2 registry.gitlab.com/mygitlabsite/nginx-config:4 *:80->80/tcp, *:443->443/tcp
q0qrhbthzdbu ui replicated 2/2 registry.gitlab.com/mygitlabsite/ui:2
bmjlip3k0iph web replicated 2/2 mynodeapp:1


My admin Vue-CLI app I added to my vue.config.js baseUrl: '/admin',
as well as in my router base: process.env.BASE_URL,



Any help appreciated










share|improve this question















I have a docker swarm setup with a parent nginx container that is open on 443 and 80 that proxies to a backend node app and a built vue cli application in a nginx container. Everything works great on that end. I want to add a 2nd vue-cli app also built with a nginx container with a path.



My parent nginx location is a simple proxy_pass



...
location /admin { # this location does not proxy
proxy_pass http://admin:80;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location /{ # this location works
proxy_pass http://ui:80;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
...


I am able to exec into the parent nginx service which is public facing and curl http://admin:80 and the html displays. I know the parent nginx service has access to the vue nginx service.



When I go to https://myurl.com/admin I get the standard 404 Not Found



My Dockerfile for the parent nginx



FROM nginx
COPY nginx.conf /etc/nginx/nginx.conf
COPY cert.crt /etc/ssl/certs/mywebsite.com.crt
COPY kk.key /etc/ssl/certs/mywebsite.com.key


My Dockerfile for the vue apps



FROM nginx
COPY dist/ /usr/share/nginx/html


My docker swarm services are all in a common overlay network on a single node.



ID                  NAME                MODE                REPLICAS            IMAGE                                                                         PORTS
hbd8mpwbxisw admin replicated 2/2 registry.gitlab.com/mygitlabsite/adminui:2
fmgx9qzlai9t nginx replicated 2/2 registry.gitlab.com/mygitlabsite/nginx-config:4 *:80->80/tcp, *:443->443/tcp
q0qrhbthzdbu ui replicated 2/2 registry.gitlab.com/mygitlabsite/ui:2
bmjlip3k0iph web replicated 2/2 mynodeapp:1


My admin Vue-CLI app I added to my vue.config.js baseUrl: '/admin',
as well as in my router base: process.env.BASE_URL,



Any help appreciated







docker nginx vue.js






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 at 19:13

























asked Nov 20 at 18:55









Varcorb

704217




704217












  • Your docker image is called registry.gitlab.com/mygitlabsite/adminui:2 (adminui instead of admin) - typo somewhere else?
    – Bennett Dams
    Nov 20 at 19:39










  • The docker swarm dns service is based on the name. I am able to curl the admin:80 and get a response.
    – Varcorb
    Nov 20 at 19:40


















  • Your docker image is called registry.gitlab.com/mygitlabsite/adminui:2 (adminui instead of admin) - typo somewhere else?
    – Bennett Dams
    Nov 20 at 19:39










  • The docker swarm dns service is based on the name. I am able to curl the admin:80 and get a response.
    – Varcorb
    Nov 20 at 19:40
















Your docker image is called registry.gitlab.com/mygitlabsite/adminui:2 (adminui instead of admin) - typo somewhere else?
– Bennett Dams
Nov 20 at 19:39




Your docker image is called registry.gitlab.com/mygitlabsite/adminui:2 (adminui instead of admin) - typo somewhere else?
– Bennett Dams
Nov 20 at 19:39












The docker swarm dns service is based on the name. I am able to curl the admin:80 and get a response.
– Varcorb
Nov 20 at 19:40




The docker swarm dns service is based on the name. I am able to curl the admin:80 and get a response.
– Varcorb
Nov 20 at 19:40












2 Answers
2






active

oldest

votes


















1














The default docker nginx conf would not work in this case. I had to create and add a nginx.conf to the admin service. The admin nginx was originally trying to get /usr/share/nginx/html/admin instead of /usr/share/nginx/html hence the 404



worker_processes 1;
events { worker_connections 1024; }
http {

sendfile on;

gzip on;
gzip_http_version 1.0;
gzip_proxied any;
gzip_min_length 500;
gzip_disable "MSIE [1-6].";
gzip_types text/plain text/xml text/css
text/comma-separated-values
text/javascript
application/x-javascript
application/atom+xml;

include /etc/nginx/mime.types;

server {
listen 80;

access_log off;
server_tokens off;

root /usr/share/nginx/html;

location / {
try_files $uri $uri/ /index.html;
}
}
}


Dockerfile:



FROM nginx
COPY dist/ /usr/share/nginx/html/admin
COPY nginx.conf /etc/nginx/nginx.conf





share|improve this answer





















  • haha I was just a little bit late
    – Siyu
    Nov 20 at 21:09





















-1














In your Dockerfile for admin, that native nginx does not know how to handle a url like http://admin:80/admin/, you can either add a config file to handle the case or strip the /admin on the proxy.



BTW better to have a trailing slash baseUrl: '/admin/'






share|improve this answer





















  • Thanks! I did try the trailing slash but it didn't make a difference
    – Varcorb
    Nov 20 at 21:14










  • no it does not, I just mean to stick to the doc
    – Siyu
    Nov 20 at 21:15











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
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',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53399721%2fhow-to-configure-nginx-in-a-container-to-access-a-built-vue-app-in-a-custom-path%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














The default docker nginx conf would not work in this case. I had to create and add a nginx.conf to the admin service. The admin nginx was originally trying to get /usr/share/nginx/html/admin instead of /usr/share/nginx/html hence the 404



worker_processes 1;
events { worker_connections 1024; }
http {

sendfile on;

gzip on;
gzip_http_version 1.0;
gzip_proxied any;
gzip_min_length 500;
gzip_disable "MSIE [1-6].";
gzip_types text/plain text/xml text/css
text/comma-separated-values
text/javascript
application/x-javascript
application/atom+xml;

include /etc/nginx/mime.types;

server {
listen 80;

access_log off;
server_tokens off;

root /usr/share/nginx/html;

location / {
try_files $uri $uri/ /index.html;
}
}
}


Dockerfile:



FROM nginx
COPY dist/ /usr/share/nginx/html/admin
COPY nginx.conf /etc/nginx/nginx.conf





share|improve this answer





















  • haha I was just a little bit late
    – Siyu
    Nov 20 at 21:09


















1














The default docker nginx conf would not work in this case. I had to create and add a nginx.conf to the admin service. The admin nginx was originally trying to get /usr/share/nginx/html/admin instead of /usr/share/nginx/html hence the 404



worker_processes 1;
events { worker_connections 1024; }
http {

sendfile on;

gzip on;
gzip_http_version 1.0;
gzip_proxied any;
gzip_min_length 500;
gzip_disable "MSIE [1-6].";
gzip_types text/plain text/xml text/css
text/comma-separated-values
text/javascript
application/x-javascript
application/atom+xml;

include /etc/nginx/mime.types;

server {
listen 80;

access_log off;
server_tokens off;

root /usr/share/nginx/html;

location / {
try_files $uri $uri/ /index.html;
}
}
}


Dockerfile:



FROM nginx
COPY dist/ /usr/share/nginx/html/admin
COPY nginx.conf /etc/nginx/nginx.conf





share|improve this answer





















  • haha I was just a little bit late
    – Siyu
    Nov 20 at 21:09
















1












1








1






The default docker nginx conf would not work in this case. I had to create and add a nginx.conf to the admin service. The admin nginx was originally trying to get /usr/share/nginx/html/admin instead of /usr/share/nginx/html hence the 404



worker_processes 1;
events { worker_connections 1024; }
http {

sendfile on;

gzip on;
gzip_http_version 1.0;
gzip_proxied any;
gzip_min_length 500;
gzip_disable "MSIE [1-6].";
gzip_types text/plain text/xml text/css
text/comma-separated-values
text/javascript
application/x-javascript
application/atom+xml;

include /etc/nginx/mime.types;

server {
listen 80;

access_log off;
server_tokens off;

root /usr/share/nginx/html;

location / {
try_files $uri $uri/ /index.html;
}
}
}


Dockerfile:



FROM nginx
COPY dist/ /usr/share/nginx/html/admin
COPY nginx.conf /etc/nginx/nginx.conf





share|improve this answer












The default docker nginx conf would not work in this case. I had to create and add a nginx.conf to the admin service. The admin nginx was originally trying to get /usr/share/nginx/html/admin instead of /usr/share/nginx/html hence the 404



worker_processes 1;
events { worker_connections 1024; }
http {

sendfile on;

gzip on;
gzip_http_version 1.0;
gzip_proxied any;
gzip_min_length 500;
gzip_disable "MSIE [1-6].";
gzip_types text/plain text/xml text/css
text/comma-separated-values
text/javascript
application/x-javascript
application/atom+xml;

include /etc/nginx/mime.types;

server {
listen 80;

access_log off;
server_tokens off;

root /usr/share/nginx/html;

location / {
try_files $uri $uri/ /index.html;
}
}
}


Dockerfile:



FROM nginx
COPY dist/ /usr/share/nginx/html/admin
COPY nginx.conf /etc/nginx/nginx.conf






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 20 at 21:07









Varcorb

704217




704217












  • haha I was just a little bit late
    – Siyu
    Nov 20 at 21:09




















  • haha I was just a little bit late
    – Siyu
    Nov 20 at 21:09


















haha I was just a little bit late
– Siyu
Nov 20 at 21:09






haha I was just a little bit late
– Siyu
Nov 20 at 21:09















-1














In your Dockerfile for admin, that native nginx does not know how to handle a url like http://admin:80/admin/, you can either add a config file to handle the case or strip the /admin on the proxy.



BTW better to have a trailing slash baseUrl: '/admin/'






share|improve this answer





















  • Thanks! I did try the trailing slash but it didn't make a difference
    – Varcorb
    Nov 20 at 21:14










  • no it does not, I just mean to stick to the doc
    – Siyu
    Nov 20 at 21:15
















-1














In your Dockerfile for admin, that native nginx does not know how to handle a url like http://admin:80/admin/, you can either add a config file to handle the case or strip the /admin on the proxy.



BTW better to have a trailing slash baseUrl: '/admin/'






share|improve this answer





















  • Thanks! I did try the trailing slash but it didn't make a difference
    – Varcorb
    Nov 20 at 21:14










  • no it does not, I just mean to stick to the doc
    – Siyu
    Nov 20 at 21:15














-1












-1








-1






In your Dockerfile for admin, that native nginx does not know how to handle a url like http://admin:80/admin/, you can either add a config file to handle the case or strip the /admin on the proxy.



BTW better to have a trailing slash baseUrl: '/admin/'






share|improve this answer












In your Dockerfile for admin, that native nginx does not know how to handle a url like http://admin:80/admin/, you can either add a config file to handle the case or strip the /admin on the proxy.



BTW better to have a trailing slash baseUrl: '/admin/'







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 20 at 21:09









Siyu

1,8771621




1,8771621












  • Thanks! I did try the trailing slash but it didn't make a difference
    – Varcorb
    Nov 20 at 21:14










  • no it does not, I just mean to stick to the doc
    – Siyu
    Nov 20 at 21:15


















  • Thanks! I did try the trailing slash but it didn't make a difference
    – Varcorb
    Nov 20 at 21:14










  • no it does not, I just mean to stick to the doc
    – Siyu
    Nov 20 at 21:15
















Thanks! I did try the trailing slash but it didn't make a difference
– Varcorb
Nov 20 at 21:14




Thanks! I did try the trailing slash but it didn't make a difference
– Varcorb
Nov 20 at 21:14












no it does not, I just mean to stick to the doc
– Siyu
Nov 20 at 21:15




no it does not, I just mean to stick to the doc
– Siyu
Nov 20 at 21:15


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53399721%2fhow-to-configure-nginx-in-a-container-to-access-a-built-vue-app-in-a-custom-path%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Tonle Sap (See)

I get strange results when I access the Sqlitedatabase with Unity C# via XAMPP

Guatemaltekische Davis-Cup-Mannschaft