Мой друг просит, чтобы я подготовил Узел. JS поддерживают на его сервере.
Вот hello.js:
#!/usr/bin/env nodejs
var https = require('https');
var fs = require('fs');
var options = {
key: fs.readFileSync('/etc/letsencrypt/live/xxxxx/privkey.pem'),
cert: fs.readFileSync('/etc/letsencrypt/live/xxxxx/cert.pem'),
ca: fs.readFileSync('/etc/letsencrypt/live/xxxxx/chain.pem')
};
https.createServer(options, function (req, res) {
res.writeHead(200);
res.end("Hello world! Node.js is working correctly on HTTPS!!\n");
}).listen(8000);
console.log('Server running at https://127.0.0.1:8080/');
Вот то, что добавляется в конфигурации сайта Appache:
ProxyRequests Off
ProxyPreserveHost On
ProxyVia Full
<Proxy *>
Require all granted
</Proxy>
<Location /nodejs>
ProxyPass https://127.0.0.1:8080
ProxyPassReverse https://127.0.0.1:8080
</Location>
"узел sudo показывает, что hello.js" показывает, что все в порядке. Я почти уверен, что проблема находится в части Apache этой проблемы. Но что?
ОБНОВЛЕННЫЙ: Некоторые новые детали. Возможно, кто-то будет видеть ошибку. Apache .conf файлы:
<VirtualHost *:80>
ServerAdmin admin@example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =example.com [OR]
RewriteCond %{SERVER_NAME} =www.example.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
ProxyRequests Off
ProxyPreserveHost On
ProxyVia Full
<Proxy *>
Require all granted
</Proxy>
<Location /nodejs>
ProxyPreserveHost On
ProxyPass https://www.example.com:8000
ProxyPassReverse https://www.example.com:8000
</Location>
<Directory "/var/www/example.com">
AuthType Basic
AuthName "Restricted Content"
AuthUserFile /etc/apache2/.htpasswd
Require valid-user
Options FollowSymLinks
AllowOverride All
</Directory>
</VirtualHost>
********
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin admin@example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
<Directory "/var/www/example.com">
AuthType Basic
AuthName "Restricted Content"
AuthUserFile /etc/apache2/.htpasswd
Require valid-user
</Directory>
</VirtualHost>
</IfModule>
Я примерил сервер и здесь являюсь двумя результатами:
sudo wget --user ime --password geslo https://www.example.com:8000
Это РАБОТАЕТ (я получаю index.html с правильным ответом из приложения Node.js).
sudo wget --user ime --password geslo https://www.example.com/nodejs
Это не РАБОТАЕТ (я получаю "nodejs" файл с кодом для содержания папки).
Какая-либо идея?
Попробуйте это в апачской конфигурации
<Location "/">
ProxyPreserveHost On
ProxyPass http://localhost:8080/
ProxyPassReverse http://localhost:8080/
</Location>
Не забывайте включать прокси и proxy_http для этого, можно использовать команду
&& sudo a2enmod proxy_http прокси sudo a2enmod
После этого необходимо перезапустить апачский сервер.