我試圖讓一個應用程序部署到我自己的服務器與mup工作在nginx後面,這樣我可以直接使用路由80端口作爲應用程序(其他東西運行在那裏的默認頁面)。流星應用程序與mup相關,後面nginx不顯示
該應用程序在http://hostname:3080上運行良好,但是當我嘗試http://hostname/dashboard時,我得到一個空白頁面。奇怪的是,兩種情況下的頁面源都完全一樣,看起來應該加載頁面。
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" class="__meteor-css__" href="/8794b5f3e7ececaa1db27feee7ff3db2d00e9dcb.css?meteor_css_resource=true">
<script type="text/javascript">__meteor_runtime_config__ = JSON.parse(decodeURIComponent("%7B%22meteorRelease%22%3A%22METEOR%401.1.0.2%22%2C%22PUBLIC_SETTINGS%22%3A%7B%7D%2C%22ROOT_URL%22%3A%22http%3A%2F%2Fhostname%22%2C%22ROOT_URL_PATH_PREFIX%22%3A%22%22%2C%22accountsConfigCalled%22%3Atrue%2C%22autoupdateVersion%22%3A%224455357f08556a49e92dd81d31c4c19d9a2204f6%22%2C%22autoupdateVersionRefreshable%22%3A%22caae7981cd6ec189870ba445ac392be58af0b0ab%22%2C%22autoupdateVersionCordova%22%3A%22none%22%7D"));</script>
<script type="text/javascript" src="/c97b1ea7dc444b12e68fdb14f80afc8a0374c861.js"></script>
</head>
<body>
</body>
</html>
我的nginx的配置如下(我只是在一瞬間測試HTTP一部分,但HTTPS位返回的自簽名的證書確定,並再次有同樣的頁面源代碼。
server_tokens off; # for security-by-obscurity: stop displaying nginx version
# this section is needed to proxy web-socket connections
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
upstream dashboard {
server 127.0.0.1:3080;
}
# HTTP
server {
listen 80 default_server; # if this is not a default server, remove "default_server"
listen [::]:80 default_server;
root /usr/share/nginx/html; # root is irrelevant
index index.php index.html index.htm; # this is also irrelevant
server_name hostname; # the domain on which we want to host the application. Since we set "default_server" previously, nginx will answer all hosts anyway.
access_log /var/log/nginx/dashboard.access;
# redirect non-SSL to SSL
location /dashboard/ {
#proxy_pass http://127.0.0.1:3080;
#proxy_pass http://hostname:3080;
proxy_pass http://dashboard/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header X-Forward-For $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
#proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
#proxy_set_header X-Forward-Proto http;
#proxy_set_header X-Nginx-Proxy true;
#proxy_redirect off;
#rewrite ^https://$server_name$request_uri? permanent;
}
}
# HTTPS server
server {
listen 443 ssl spdy; # we enable SPDY here
server_name hostname; # this domain must match Common Name (CN) in the SSL certificate
#root html; # irrelevant
#index index.html; # irrelevant
ssl_certificate /etc/nginx/ssl/dashboard.crt;
ssl_certificate_key /etc/nginx/ssl/dashboard.key;
# performance enhancement for SSL
ssl_stapling on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 5m;
# safety enhancement to SSL: make sure we actually use a safe cipher
ssl_prefer_server_ciphers on;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:ECDHE-RSA-RC4-SHA:ECDHE-ECDSA-RC4-SHA:RC4-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!3DES:!MD5:!PSK';
# config to enable HSTS(HTTP Strict Transport Security) https://developer.mozilla.org/en-US/docs/Security/HTTP_Strict_Transport_Security
# to avoid ssl stripping https://en.wikipedia.org/wiki/SSL_stripping#SSL_stripping
add_header Strict-Transport-Security "max-age=31536000;";
# If your application is not compatible with IE <= 10, this will redirect visitors to a page advising a browser update
# This works because IE 11 does not present itself as MSIE anymore
if ($http_user_agent ~ "MSIE") {
return 303 https://browser-update.org/update.html;
}
# pass all requests to Meteor
location /dashboard/ {
proxy_pass http://127.0.0.1:3080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade; # allow websockets
proxy_set_header Connection $connection_upgrade;
proxy_set_header X-Forwarded-For $remote_addr; # preserve client IP
# this setting allows the browser to cache the application in a way compatible with Meteor
# on every applicaiton update the name of CSS and JS file is different, so they can be cache infinitely (here: 30 days)
# the root path (/) MUST NOT be cached
if ($uri != '/') {
expires 30d;
}
}
}
其中hostname是由我代替實際的主機名稱。
訪問日誌文件似乎說它獲取代碼確定,但有一些奇怪的404在那裏,我不知道。
150.xxx.xxx.xx - - [29/May/2015:14:24:14 +1000] "GET /8794b5f3e7ececaa1db27feee7ff3db2d00e9dcb.css?meteor_css_resource=true HTTP/1.1" 404 136 "http://hostname/dashboard/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:38.0) Gecko/20100101 Firefox/38.0"
150.xxx.xxx.xx - - [29/May/2015:14:24:14 +1000] "GET /c97b1ea7dc444b12e68fdb14f80afc8a0374c861.js HTTP/1.1" 404 136 "http://hostname/dashboard/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:38.0) Gecko/20100101 Firefox/38.0"
任何想法從哪裏走?
所以如此接近...感謝提示。我認爲問題是ROOT_URL。我現在已經獲得了模板加載,但是路由被炸燬,出現錯誤'Oops,看起來沒有客戶端或服務器上的路由:「http:// hostname/dashboard /。」,這是正確的因爲URL當然是http:// hostname/dashboard「,我在應用程序的主頁有一個'/'的路線。有沒有辦法解決這個問題,或者我更好地使用子域名嗎? –
OK,working它出來..這將對路由造成嚴重破壞,因爲它看起來好像我必須通過nginx將它們全部轉發。我認爲子域名是更好的選擇..感謝讓我這麼做 –
我的榮幸。我有一個困難的時間包裹着我的頭。是的,與'/ meteor_app'路線相比,子域是一個更容易設置的選項,但是一旦它到位,它不應該導致進一步的問題。:) – ziggrat