naltatis / micro-frontends-in-action-code

The Tractor Store - sample code from the book Micro Frontends in Action
https://the-tractor.store
MIT License
411 stars 155 forks source link

Issues running on Ubuntu 20.10 #11

Closed iancharlesdouglas closed 1 year ago

iancharlesdouglas commented 3 years ago

When I run the Node examples using Nginx on Ubuntu 20.10 I get the following error (as a user in the terminal):

> micro-frontends-in-action-code@1.0.0 04_routing /home/ian/dev/micro-frontends/micro-frontends-in-action-code
> concurrently --names "nginx  ,decide ,inspire" "node nginx.js 04_routing/webserver/nginx.conf" "mfserve --listen 3001 04_routing/team-decide" "mfserve --listen 3002 04_routing/team-inspire" "wait-on http://localhost:3000/product/porsche && opener http://localhost:3000/product/porsche"

[nginx  ] 📮 ERROR: Unable to start Nginx
[nginx  ] nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (13: Permission denied)
[nginx  ] 
[nginx  ] 🦑 Is Nginx installed?
[nginx  ] Install it via your system's package manager.
[nginx  ] e.g. $ sudo apt-get install nginx

To get around the permission issue I ran as root (in IntelliJ IDEA) but then I get:

> micro-frontends-in-action-code@1.0.0 05_ssi /home/ian/dev/micro-frontends/micro-frontends-in-action-code
> concurrently --names "nginx  ,decide ,inspire" "node nginx.js 05_ssi/webserver/nginx.conf" "mfserve --listen 3001 05_ssi/team-decide" "mfserve --listen 3002 05_ssi/team-inspire" "wait-on http://localhost:3000/product/porsche && opener http://localhost:3000/product/porsche"

[nginx  ] 📮 ERROR: Unable to start Nginx
[nginx  ] nginx: [emerg] open() "/dev/stdout" failed (6: No such device or address)
[nginx  ] 
[nginx  ] 🦑 Is Nginx installed?
[nginx  ] Install it via your system's package manager.
[nginx  ] e.g. $ sudo apt-get install nginx

The book advises just to install Nginx -- no configuration is necessary. I reinstalled it but to no avail.

Please advise.

hurzelpurzel commented 3 years ago

Got the same problem. But now I got it working by comment the access_log declaration at 04_routing/webserver/nginx.conf. The problem that its just runs with root user only still remains. Even www-data as user (default for nfinx service) was not possible.

# comment out on windows
#access_log /dev/stdout compact;

Starting the app using

 sudo -u root  npm run 04_routing  
did the job, even the scripts complains about opening the browser is not possible, but you can do it by your self.

hurzelpurzel commented 3 years ago

Final solution which solve all the problems was the following.

daemon off;
error_log  /tmp/error.log;
pid        /tmp/nginx.pid;
events {}

http {
  upstream team_decide {
    server localhost:3001;
  }

  upstream team_inspire {
    server localhost:3002;
  }

  log_format compact ':3000$uri $status';

  server {
    listen 3000;

    # comment out on windows
    access_log /tmp/access.log compact;

    location /product/ {
      proxy_pass  http://team_decide;
    }

    location /decide/ {
      proxy_pass  http://team_decide;
    }

    location /recommendations {
      proxy_pass  http://team_inspire;
    }

    location /inspire/ {
      proxy_pass  http://team_inspire;
    }
  }
}

I found that by visiting the full example at https://www.nginx.com/resources/wiki/start/topics/examples/full/. This sets log an Pid files to /tmp which is accessible for all users by default.

trevorgithub commented 3 years ago

Thanks @hurzelpurzel . Dumb question - where do I put that configuration? I see under 04_routing/webserver there's a nginx.conf. I tried updating that, but it didn't seem to help.

hurzelpurzel commented 3 years ago

IT's is a little bit Agora. But I Think the Problem was that the logfiles were not in a Folder where nginx was able to write. My example focus on tje Routing case. When you got the same Problem in one of the other examples, you must adress the nginx,conf there and adjust it accordingly. Even running with südöstlich should work instead

trevorgithub @.***> schrieb am Fr., 28. Mai 2021, 04:37:

Thanks @hurzelpurzel https://github.com/hurzelpurzel . Dumb question - where do I put that configuration? I see under 04_routing/webserver there's a nginx.conf. I tried updating that, but it didn't seem to help.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/naltatis/micro-frontends-in-action-code/issues/11#issuecomment-850068401, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADACKDWBHI6AI45BUOTFBF3TP36YHANCNFSM4URBOZYQ .

trevorgithub commented 3 years ago

Yeah, what you did makes sense. It's just that after modifying 04_routing/webserver/nginx.conf to look like your sample nginx config above, and then running npm run 04_routing, it still complains:

nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (13: Permission denied)

This despite the fact that I look at package.json, and for the 04_routing script, I see:

"04_routing": "concurrently --names \"nginx ,decide ,inspire\" \"node nginx.js 04_routing/webserver/nginx.conf\" \"mfserve --listen 3001 04_routing/team-decide\" \"mfserve --listen 3002 04_routing/team-inspire\" \"wait-on http://localhost:3000/product/porsche && opener http://localhost:3000/product/porsche\"",

So, it looks like it should be referencing the nginx.conf in the 04_routing/webserver folder.

I did try sudo npm run 04_routing and that did get past the original problem. It introduce a 2nd problem though:

Running Firefox as root in a regular user's session is not supported.

I could work around this problem by taking the URL the script tried to load, and manually copying it into the browser:

http://localhost:3000/product/porsche

Thanks for the help!

trevorgithub commented 3 years ago

@hurzelpurzel, well I spoke too soon. Running as sudo did work for 04_routing example. But once I got to the next chapter, 05_ssi, it fails:

nginx: [emerg] open() "/dev/stdout" failed (6: No such device or address)

I can confirm that 05_ssi/webserver/nginx.conf contains the ssi on feature. So, I'm quite sure that's the intended configuration file.

If I run npm run 05_ssi without sudo, then the error message is different:

nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (13: Permission denied)

I tried commenting out this line in 05_ssi/webserver/nginx.conf:

access_log /dev/stdout compact;

Since there's a comment mentioning that it should be commented out in Windows (even though I'm on Ubuntu), but no luck.

It's clearly a file permission issue, but I'm not sure what's going wrong. Any further suggestions?

EDIT: Oh, wait. It still works with sudo, provided I comment out the line above