NGINX没有打开Parse Server和Socket.io的端口

时间:2018-09-11 22:00:53

标签: nginx socket.io digital-ocean parse-server

我已经在Ubuntu 16.04.4 x64上的DigitalOcean.com上使用Socket.io安装了Parse Server

在HTTP上一切正常

然后我决定通过SSL协议建立与服务器的连接,因此我安装了具有Let's Encrypt证书的NGINX。

NGINX可以正常工作,当我在浏览器mydomain.com中输入内容时,我可以看到NGINX徽标和https连接。在这种情况下,一切正常,但端口1337和端口3000上的套接字无访问权限。

看起来像NGINX的人不知道他需要让解析服务器和套接字打开所需的端口。

我是iOS开发人员,看来我做错了事

任何帮助将不胜感激!

我以前用来安装所有内容的教程

解析服务器: https://www.digitalocean.com/community/tutorials/how-to-run-parse-server-on-ubuntu-14-04

解析服务器 https://www.digitalocean.com/community/tutorials/how-to-migrate-a-parse-app-to-parse-server-on-ubuntu-14-04#step-3-%E2%80%93-install-and-configure-parse-server-and-pm2

NGINX和证书 https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-14-04

这是我的NGINX配置(example.com = mydomain.com)

server {

# SSL configuration

# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;

root /var/www/html;

# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;

server_name example.com www.example.com;

location / {
    # First attempt to serve request as file, then
    # as directory, then fall back to displaying a 404.
    try_files $uri $uri/ =404;
}

location /parse/ {
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-NginX-Proxy true;
    proxy_pass http://localhost:1337/;
    proxy_ssl_session_reuse off;
    proxy_set_header Host $http_host;
    proxy_redirect off;
}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
#   include snippets/fastcgi-php.conf;
#
#   # With php7.0-cgi alone:
#   fastcgi_pass 127.0.0.1:9000;
#   # With php7.0-fpm:
#   fastcgi_pass unix:/run/php/php7.0-fpm.sock;
#}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
#   deny all;
#}

listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}

这是我的Parse Server初始化

var api = new ParseServer({
databaseURI: 'mongodb://localhost:27017/admin',
cloud: __dirname + '/cloud/main.js',
appId: 'appId',
masterKey: 'masterKey',
serverURL: 'https://example.com:1337/parse',
liveQuery: {
classNames: ["Posts", "Comments"] // List of classes to support for query subscriptions
  }
});

var port = 1337;
var parseServer = require('https').createServer(app);
parseServer.listen(port, function() {
     console.log('parse-server-example running on port ' + port + '.');
});

//Socket.io
const socketIO = require('socket.io');
const socketPort = 3000;
var socketServer = require('https').createServer(express());
socketServer.listen(socketPort, function(){
     console.log('listening on *:'+socketPort);
});

1 个答案:

答案 0 :(得分:0)

好吧,终于我找到了问题和解决方法。

我发现了Parse Dashboard问题案例#429 (Getting dashboard to run through https)

我知道我的Parse Server需要告知NGINX,他需要在SLL中运行并提供我使用“让我们加密”创建的证书。

这是正确的代码:

<script>
  //get currency
  var amountCurrency = document.getElementById('userCurrency');
  console.log(amountCurrency);
</script>

与Socket.io的概念相同

    var fs = require('fs'); 
    var https = require('https'); 
    var express = require('express'); 
    var ParseServer = require('parse-server').ParseServer; 
    var ParseDashboard = require('parse-dashboard'); 
    var path = require('path'); 
    var app = express(); 
    var port = 1337; 
    var options = { key: fs.readFileSync(path.resolve(__dirname, '/etc/letsencrypt/live/sitedomain/privkey.pem')),
                   cert: fs.readFileSync(path.resolve(__dirname, '/etc/letsencrypt/live/sitedomain/fullchain.pem')), }; 

    var parse = new ParseServer({ databaseURI: 'mongodb://localhost:540556/admin', 
    cloud: __dirname + '/cloud/main.js', 
    appId: 'appId', 
    masterKey: 'masterKey', 
    serverURL: 'https://example.com', 
    liveQuery: { classNames: ["Posts", "Comments"] // List of classes to support for query subscriptions } }); 

    var app = express(); 
    app.use('/public', express.static(path.join(__dirname, '/public'))); 
    app.use('/parse', parse); 
    app.get('/', function(req, res) { res.status(200).send('404'); });
    var server = https.createServer(options, app).listen(port, function() { 
    console.log("server listening on port " + port); 
    });

所有NGINX配置均正确

我浪费了很多时间,却没有在网络中找到类似的解决方案。

希望它将对某人有所帮助。

致谢。