[英]setting up nginx with node js using express
trying to set up my nginx server to pass urls over to nodejs and have nodejs send a json feed back to the browser. 尝试设置我的Nginx服务器以将URL传递给nodejs,并让nodejs将json提要发送回浏览器。 I added this to my nginx server so only if the url contains /boba/whatever will it send it to the node server.
我将其添加到我的nginx服务器中,因此仅当URL包含/ boba /时,它将发送到节点服务器。
location ~ ^/boba {
proxy_pass http://localhost:3005;
proxy_http_version 1.1;
}
and my nodejs script is written like this 我的nodejs脚本是这样写的
var express = require('express');
var app = express();
app.get('/boba/', function(req, res) {
console.log("you did it!");
res.json({
thumbnail: '.jpg'
});
});
console.log("END");
app.listen(process.env.PORT || 3005);
I get a file not found when I try to load it in the browser. 尝试在浏览器中加载文件时,找不到文件。 I'm not sure if I need to have boba still included in the url in nodejs or just the root like this / .
我不确定我是否需要将boba仍然包含在nodejs的URL中,还是仅包含像这样的根。 Or if it should be something else.
或者是否应该是其他东西。 Any help
任何帮助
This is what worked for me: 这对我有用:
http {
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=one:8m max_size=3000m inactive=600m;
proxy_temp_path /var/tmp;
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
gzip on;
gzip_comp_level 6;
gzip_vary on;
gzip_min_length 1000;
gzip_proxied any;
gzip_types text/plain text/html text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
gzip_buffers 16 8k;
}
upstream myserver {
server 127.0.0.1:3000;
keepalive 64;
}
server {
listen 80;
server_name http://www.myServer myServer;
#error_page 502 /errors/502.html;
location ~ ^/(images/|img/|javascript/|js/|css/|stylesheets/|flash/|media/|static/|font/|robots.txt|humans.txt|favicon.ico) {
root /var/www/html/myServer/public;
access_log off;
expires max;
}
#location /errors {
# internal;
# alias /usr/local/silly_face_society/node/public/errors;
#}
location / {
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_set_header Connection "";
proxy_http_version 1.1;
proxy_cache one;
proxy_pass myserver;
}
}
Just make sure routes are pointing to your localhost routes. 只要确保路由指向您的本地主机路由即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.