I have created a testApp using express.js in a server containing nodeJS environment. Site is running in the http://localhost:3000 And i have checked the output via command line -
curl http://localhost:3000/
Output-
<!DOCTYPE html>
<html>
<head>
<title>Express</title>
<link rel="stylesheet" href="/stylesheets/style.css">
</head>
<body>
<h1>Express</h1>
<p>Welcome to Express</p>
</body>
</html>
But i couldn't find it in my domain. It is showing an error like this -
Not Found
404
Error: Not Found
at /home/user/testApp/app.js:30:13
at Layer.handle [as handle_request] (/home/user/testApp/node_modules/express/lib/router/layer.js:95:5)
at trim_prefix (/home/user/testApp/node_modules/express/lib/router/index.js:312:13)
at /home/user/testApp/node_modules/express/lib/router/index.js:280:7
at Function.process_params (/home/user/testApp/node_modules/express/lib/router/index.js:330:12)
at next (/home/user/testApp/node_modules/express/lib/router/index.js:271:10)
at /home/user/testApp/node_modules/express/lib/router/index.js:618:15
at next (/home/user/testApp/node_modules/express/lib/router/index.js:256:14)
at Function.handle (/home/user/testApp/node_modules/express/lib/router/index.js:176:3)
at router (/home/user/testApp/node_modules/express/lib/router/index.js:46:12)
What could be the possible reason for such kind of error ?
EDIT:
App Structure:
.
app.js
bin
www
package.json
public
images
javascripts
stylesheets
style.css
routes
index.js
users.js
views
error.jade
index.jade
layout.jade
Ngynx configuration file:
server {
listen 80;
server_name 10.10.10.15;
location / {
proxy_pass http://localhost:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
location /testApp {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
Related
I installed react app on nginx server and build it (it's ok, i followed the instructions),
but i have this problem=>
https://xx.xxx.xx.xxx/static/css/main.6094b2de.css net::ERR_CONNECTION_REFUSED
https://xx.xxx.xx.xxx/static/js/main.524d9c99.js net::ERR_CONNECTION_REFUSED
etc...
I guess the problem is that the request is sent to https ,because if a follow this link in browser
< https://xx.xxx.xx.xxx/static/css/main.6094b2de.css > and change https to http i get some data
`
server {
listen 80;
location / {
root /var/www/myWebsite/client/;
index index.html index.htm;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
try_files $uri $uri/ /index.html;
}
location /api {
proxy_pass http://xx.xxx.xx.xxx:8800;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
`
any ideas?
for HTTPS you need to add an SSL certificate using let's encrypt
please check this blog
I am going to run node app on nginx.
Here is nginx configuration.
location /first {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
And here is node app router.
app.use('/', indexRouter);
app.use('/api', apiRouter);
But when I access server via x.x.x.x/first
I get 404 errors.
What is the reason.
Please let me know if you know.
I've been trying to host my website (a Node app) and my Ghost blog on the same Digital Ocean droplet. I've got Nginx all set up so that requests to '/' are sent to port 8080 where my site is being served and requests at '/blog' are sent to 2368, Ghost's default port number.
The problem is that the Ghost installation doesn't seem to be able to find the assets folder in its directory. The base HTML content shows up, but devoid of styling. I've tried configuring the root to point to the subdirectory Ghost resides in to no avail.
This is an error I'm getting (404s throughout):
GET http://MYURL/assets/css/screen.css?v=59384a3875
MYURL/:126
404 (Not Found)
Picture: HTML content appears, but no styling
Nginx Config:
server {
listen 80;
server_name MYURL;
location / {
proxy_pass http://localhost:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
location /blog {
rewrite ^/blog(.*) /$1 break;
proxy_pass http://localhost:2368;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
Ghost Production Config:
var path = require('path'),
config;
config = {
// ### Production
// When running Ghost in the wild, use the production environment.
// Configure your URL and mail settings here
production: {
url: 'http://MYURL',
mail: {},
database: {
client: 'sqlite3',
connection: {
filename: path.join(__dirname, '/content/data/ghost.db')
},
debug: false
},
server: {
host: '127.0.0.1',
port: '2368'
}
},
Any help is greatly appreciated.
You are using /assets/css/screen.css?v=59384a3875 which is not proxied I mean you did not yet added location /assets but still using. You need to add another location directive for assets like your nginx config would be
server {
listen 80;
server_name MYURL;
location / {
proxy_pass http://localhost:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
location /assets {
proxy_pass http://localhost:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
location /blog {
rewrite ^/blog(.*) /$1 break;
proxy_pass http://localhost:2368;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
another solution
You may like to remove / from all static content like use assets/css/screen.css?v=59384a3875 rather than /assets/css/screen.css?v=59384a3875 but you have remove from everywhere in html, js, css, etc.
I installed nginx to serve multiple nodejs apps
On my server I have 2 apps myapp and pm2-web
the nginx config look like this
http {
# .... logs, gzip ... etc
server {
location / {
proxy_pass http://localhost:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
location /pm2 {
proxy_pass http://localhost:9000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
my app runs fine but when I try to access /pm2
I get the following error
Cannot GET /pm2
when pm2-web is not running I get 502 Bad Gateway
But I can still access pm2 from http://IP:9000
The /pm2 part of the URL is being passed through to your Node application, where it does not match any paths.
ie, your pm2 app is running on 9000, but you are trying to access http://localhost:9000/pm2 which doesn't exist.
Include a trailing slash in your proxy pass URL to ensure /pm2 is not being included:
location /pm2 {
proxy_pass http://localhost:9000/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
Tutorials and other answers doesn't help. I know that thing is in nginx config, but where?
I have CentOS 6.5, nginx 1.4.4, node 0.10.24, socket.io.js 0.9.16 and
in my_server_nginx.conf, node section:
location ~ /node {
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
in app.js:
var io = require('/usr/lib/node_modules/socket.io/lib/socket.io').listen(3000);
in html:
<script type="text/javascript" src="/node/socket.io/socket.io.js"></script>
in browser console:
Uncaught ReferenceError: io is not defined
Direct open /node/socket.io/socket.io.js returns
Welcome to socket.io.
In this case, '/node/socket.io/socket.io.js' is your socket root directory. and the socket.io js file will be served from within there. try linking to '/node/socket.io/socket.io.js/socket.io.js'