How to configure weinre behind Nginx proxy? - node.js

I have the latest weinre installed (2.0.0-pre-I0Z7U9OV). I can start it, all is working fine, but I need to run it behind a Nginx Proxy to be able to use a trusted SSL Certificate. So what I tried is the following:
upstream weinre {
server 127.0.0.1:8080;
}
server {
...
location /weinre/ {
proxy_pass http://weinre/;
proxy_set_header Host $host;
}
}
The site is opening, all fine, but when adding the target script to my mobile page, I can't see it appear in the targets list. So I started to dig into it and found the follwing in the Chrome console:
POST https://domain.net/ws/target 404 (Not Found)
Why is it POSTing to ws/target and not weinre/ws/target? Since everything else is working under the weinre sublocation.
Is it even possible to run weinre under such setup?

Not quite sure what's going on there; what is the URL of the of the target script you are embedding in your page? It's possible to override the URL of the weinre server, instead of having it calculated from the target script, by setting the global window.WeinreServerURL, as you can see in the Target.coffee file. You can see how the server URL is used to get the URL to the "socket" URL here.

Related

ReactDOM not rendering anything from separate js file

I used "npx create-react-app testreact" to create a react project. When testing from browser on my PC, the server returns a blank page, other than the expected words —— "Learn React".
What's happening here? how to fix it?
Cmd Sequnce
npx create-react-app testreact
npm install
npm start
Env Info
nodejs: v13.2.0
npm: 6.13.1
system: 18.04.1-Ubuntu
reverse proxy server: nginx
Code Info
repo: https://github.com/nautilusshell/testreact.git
there is folder called node_modules which was created by "npm install", I didn't put into above repo because it is too big and not necessary to upload.
by the way, actually I didn't change anything.
Err Info
visit http://52.130.83.55/image_editing
from browser I got:
the .js files whose status equal 404 all locates at http://52.130.83.55/static/js/xxx.js. This path was told by my chrome browser, but I searched my server, by command
find / -name "0.chunk.js" 2>/dev/null, only to find that there are no such files.
For example, http://52.130.83.55/static/js/0.chunk.js was not found anywhere on my server.
Nginx Config
repo: https://github.com/nautilusshell/nginx_config.git
Your nginx configuration has the following block:
location /image_editing {
proxy_set_header Host $host;
proxy_set_header x-forwarded-for $remote_addr;
proxy_set_header X-Real-IP $remote_addr;
client_max_body_size 1000M;
proxy_pass http://image_editing;
}
This block presumably points anyone who visits [hostname]/image_editing is shown your React App, however it does not rewrite the path. This means that if you visit localhost/image_editing, the path is still /image_editing in the browser.
Any paths to assets, such as /static/js/bundle.js (note the leading slash), which is used by default by CRA, will not go to the webserver hosted by Create React App but instead will hit Nginx itself. You have no configuration to forward requests to /static to the same server as /image_editing, so all of those requests will fail.
In other words, when you visit yourdomain/image_editing, the index.html of your React app is sent back declaring that all of the assets are located at http://yourdomain/static. This request hits Nginx and Nginx correctly serves 404 because it does not know about those assets. You need to configure your React App such that it 'thinks' that the assets are actually located at http://yourdomain/image_editing/static/.
To solve this, you need to modify the publicPath property of the webpack configuration of your project. Unfortunately, this will require ejecting your Create React App configuration using npm eject.
You could also resolve this on the Nginx side using subdomains. For example, you could host your image editing app at image-editing.yourdomain.com and all of the URLs with leading slashes would resolve correctly.

need help on nginx configuration for nodejs api

my node api starts on port 1337 and works fine. if I browse localhost:1337 my api return nothing and if I browse localhost:1337/products my api actually works fine and return my products list as Json.
now service nginx installed and configured well to reverse-proxy of localhost:1337 to localhost
so after opening localhost it somehow works and says nothing as before but if I try browsing localhost/products again says nothing
and don't care about products.
I just have found the issue.
in nginx default configuration removed everything in section location /api/ just copy proxy_pass http://localhost:1337/; lonely. and it works correctly.

Install Ghost Blog

I've been trying to get Ghost.io installed on my web server for quite sometime. I have a VPS with Centos 6 and Cpanel.
Today I found a script at http://www.allaboutghost.com/one-click-ghost-install-script/ that said you could just enter a command into your ssh terminal and have it all installed for you.
Command
wget -O - https://raw.github.com/howtoinstallghost/installghost.sh/master/installGhost.sh | sudo bash
I did this and it appears to have worked, I didn't get any errors but now I am not able to find the install in either FileZilla or by using my web browser. The website says that it installs in the /var/www/ghost/ directory but I can't find that. If I use cd /var/www/ghost/ in the ssh it takes me right to it and even lets me edit the config.example.js file.
If I direct my browser to www.mydomain.com:80 since the site says it installs on port 80 it just takes me back to my home page.
What am I missing and what do I need to do?
As Per the comments, I did follow the instructions on the github page. Now All I get when I visit mydomainname.com/ghost/
Ghost is installed really easy. You'd better don't use 3rd party scripts for that as it might really vary from system to system. All you need is to get Node.js installed and then follow instruction for example from here: https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-ghost-on-ubuntu-16-04. They are very detailed and must work for Centos as well.
Most common errors are:
- Not configuring a reverse proxy (nginx or apache) to link to your ghost install on port 2368. Here is an example for Nginx:
server {
listen 80;
server_name your_domain_or_ip_address;
location / {
proxy_set_header HOST $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:2368;
}
}
If you now see default home page it means some web server is already running and intercept all the requests and parks them to a default location (e.g. /var/www)
- If you want Ghost to be the one and the only web server on your VPS, you have to remove or shut down currently installed web server and try to configure ghost to answer on port 80 like this:
server: {
host: '0.0.0.0',
port: '80'
}
I didn't test it but has to work. This kind of install is not recommended and insecure. I suppose you can configure reverse proxy from Cpanel, but not sure.
The best and easiest way to set up Ghost is using SSH.
Hope it helps. For any further help, you have to provide more details and possibly logs and configs. Most of the possible errors you'll catch when installing or starting your blog with npm
sudo npm install --production
sudo npm start --production
Good luck with your deployment.
Hey you don't need to do that much you can just launch ghost from digitalpress for free...
Know how to host ghost blog for free out here : https://treanches.digitalpress.blog/hosting-ghost-blog/
You can think this as self promotion but this article is so much understanding you won't regret reading it

Nginx + node.js configuration

I need the right configuration of nginx for my problem.
Suppose the nginx + nodejs serverprograms are running on the same debian machine.
Domain name for my website is for simplicity just webserver.com (and www.webserver.com as alias)
Now, when someone surfs on the internet to "webserver.com/" it should pass the request to the nodejs application which should run on a specific port like 3000 for example. But the images and css files should get served by nginx as static files and the filestructure should looke like webserver.com/images or webserver.com/css .. images + css should get served by nginx like a static server
Now it gets tricky:
But when someone surfs on webserver.com/staticsite001 or webserver.com/staticsite002 then it should get served by the nginx server only. no need for nodejs then.
And for the nodejs server, I am just setting up my nodejs application with port 3000 for example to receive the bypass from nginx for webserver.com/
to put it in a more understandable language: when someone surfs to webserver.com/staticsite001 it should NOT pass it to the node application. It should only pass it to the node application if its inside of the first webserver.com/ directory that the outsiders can see. The webserver.com/staticsite001 should only get serverd by nginx.
How, how do I do that ? And what should the http and server block look like for the nginx configuration look like?
I am familiar with nodejs. But I am new to nginx and new to reverse proxying.
thanks
the file structure on the debian hard drive looks like:
/home/wwwexample/staticsite001 (for www.webserver.com/staticsite001/) only handled by nginx
/home/wwwexample/staticsite002 (for www.webserver.com/staticiste002/) only handlex by nginx
/home/wwwexample/images
/home/wwwexample/css
and in
/home/nodeapplication is my node js application
This server block should work:
server {
listen 80;
server_name webserver.com www.webserver.com;
root /home/wwwexample;
location / {
proxy_pass http://localhost:3000;
proxy_set_header Host $host;
}
location /staticsite001 {
}
location /staticsite002 {
}
location /images {
}
location /css {
}
}
First location makes nginx to proxy everything to localhost:3000. Following empty locations instruct nginx to use default behavior, that is to serve static files.
Put this code into file /etc/nginx/sites-available/my-server and create a symlink to it in /etc/nginx/sites-enabled. There is a default config, which you could use as a reference.
After that you could use command sudo /usr/sbin/nginx -t to check configuration. If everything is OK use /etc/init.d/nginx reload to apply new configuration.

Can't get to my nodejs server through web browser

Alright, so I setup a node.js server quite a while ago on a AWS EC2 micro server. I was completely new to it and followed various tutorials to get it up and running. It used nginx as a reverse proxy (I believe) and the server was listening on port 8124.
Now, the instance got restarted and I can't for the life of me get access to my server back. I can ssh to it. I can start the server. I can send POST/PUT requests to it through my local command line, but my web browser gives me the 404 nginx page.
This is driving me up the wall - where in the browser/nginx/nodejs chain are things breaking down?
Please help - I'm horribly new at this at it must be a single line somewhere that's broken. I just don't know enough to find it.
My /etc/nginx/sites-enables/default file simply contains
location / {
proxy_pass http://127.0.0.1:8124/;
}
Okay I figured it out. I had to go directly into /etc/nginx/nginx.conf and in the server that was there
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
I added the line
proxy_pass http://127.0.0.1:8124/;
Oh thank god. That was going to kill me.

Resources