我继续在webfaction和本地网络服务器上的网络服务器上获得502所有样式表和图片。我不确定我做错了什么?我必须在生产网络服务器上点击3次才能正确加载所有资源。有帮助吗?我的页面上有大图片,但我认为它们不会导致问题。
这些是我在生产服务器上的响应标题
Connection:keep-alive
Content-Encoding:gzip
Content-Type:text/html; charset=utf-8
Date:Sun, 08 Dec 2013 07:47:55 GMT
Server:nginx
Transfer-Encoding:chunked
Vary:Accept-Encoding
X-Powered-By:Express
这是我在节点上的app.js.
var pagejs= '../routes';
var express = require('express')
, home = require(pagejs)
, user = require(pagejs+'/user')
, http = require('http')
, path = require('path')
, events = require(pagejs+'/events')
, contact= require(pagejs+'/contact')
, abouttedx = require(pagejs+'/about')
, sponsor = require(pagejs+'/sponsors')
, gzippo = require('gzippo');
var app = express();
function viewConfig(app){
app.set('views', __dirname + './../views');
app.set('view engine', 'jade');
//app.use(express.favicon());
app.use(express.favicon(path.join(__dirname + './../public/images/favicon.ico')));
app.use(express.logger('dev'));
//app.use(express.bodyParser());
app.use(express.json());
app.use(express.urlencoded());
app.use(express.methodOverride());
app.use(app.router);
//app.set('view options', {layout: false });
//app.use(express.static(path.join(__dirname, './../public')));
app.use(gzippo.staticGzip(path.join(__dirname, './../public')));
app.use(gzippo.compress());
app.set('port', process.env.PORT || 9000);
}
app.configure('production', function(){
viewConfig(app);
});
app.configure('development', function(){
app.use(express.errorHandler());
viewConfig(app);
});
app.get('/', home.index);
app.get('/users', user.list);
app.get('/events', events.eventspage);
app.get('/about', abouttedx.aboutpage);
app.get('/sponsor', sponsor.sponsorpage);
app.get('/contact', contact.contactuspage);
http.createServer(app).listen(app.get('port'), function(){
console.log("Express server listening on port " + app.get('port'));
});
答案 0 :(得分:0)
我假设myapp.com
是我们要设置的网络应用程序。
在/etc/nginx/sites-enabled/myapp.com
中检查您的服务器配置。适应它类似于此;
server {
server_name myapp.com;
# set nginx root to public dir of your express server
root /var/www/myapp/releases/current/public/;
index index.html index.htm;
access_log /var/log/nginx/myapp.access.log;
error_log /var/log/nginx/myapp.error.log;
location ~ ^/(js|css|images|media|system)/ {
autoindex off;
add_header Cache-Control public;
expires 4w;
}
location / {
try_files $uri $uri/index.html @proxy;
}
location @proxy {
# set proxy pass to your node server
proxy_pass http://127.0.0.1:3000;
}
}
测试nginx配置并重新加载;
sudo nginx -t
sudo nginx -s reload
现在nginx收到您的请求并将其代理到您的节点服务器。如果这对您有用,请告诉我。如果它仍然不起作用,您可以共享您的nginx配置。