我正在尝试通过Node.js协议在我的服务器上运行一个HTTPS + Vue.js + Apache + MySQL应用程序。(在本地或通过HTTP在服务器上运行良好)。
有一个API的URL (子域),它返回一个JSON结果,假设是"api.mysite.com“。
我尝试了不同的方法,现在我在我的app.js中使用端口443 (它没有帮助):
const PORT = process.env.PORT || 443
app.listen(PORT, () => {
console.log(`Server stated on port ${PORT}`)
})在我的本地机器上,我使用5000端口,并通过"http://locahost:5000“访问应用程序(它工作得很好)。
"/etc/apache2/sites-available/my-site-api.conf":
<VirtualHost *:80>
ServerName api.mysite.com
ServerAlias api.mysite.com
DocumentRoot /var/www/mysite/api
RewriteEngine on
RewriteCond %{SERVER_NAME} =api.mysite.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>"/etc/apache2/sites-available/my-site-api-le-ssl.conf":
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName api.mysite.com
ServerAlias api.mysite.com
DocumentRoot /var/www/mysite/api
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
# Some rewrite rules in this file were disabled on your HTTPS site,
# because they have the potential to create redirection loops.
# RewriteCond %{SERVER_NAME} =api.mysite.com [OR]
# RewriteCond %{SERVER_NAME} =api.mysite.com
# RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/api.mysite.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/api.mysite.com/privkey.pem
</VirtualHost>
</IfModule>如果你需要任何其他信息,请告诉我。
提前谢谢你!
发布于 2020-07-19 14:18:28
看起来Apache和你的应用都被配置为侦听端口443。我假设您得到的本质错误是每个端口应该只有一个监听程序,并且它告诉您443已经被apache占用。
如果你想在HTTPS/443下公开你的应用程序,我有两种方法
ProxyPass "/" "http://localhost:5000"更多详细信息请访问:Enabling HTTPS on express.js
https://stackoverflow.com/questions/62976872
复制相似问题