151*_*291 3 nginx node.js express
我正在使用node和express,AWS Ec2 Linux并在端口号8080和8081使用中运行两个网络应用程序pm2。
将子域添加到我的弹性 IPadmin.example.com和app.example.com.
我的两个应用程序都在 localhost:8080 和 8081 中运行。
/etc/nginx/conf.d/virtual.conf // 编辑后
server {
listen admin.example.com:80;
server_name admin.example.com;
location / {
proxy_pass http://localhost:8080;
}
}
Run Code Online (Sandbox Code Playgroud)
/etc/nginx/conf.d/virtual.conf // 编辑前
#
# A virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
Run Code Online (Sandbox Code Playgroud)
服务器.js
const express = require('express');
const bodyParser = require('body-parser')
const path = require('path');
const app = express();
app.use(express.static(path.join(__dirname, 'build')));
app.get('/login', function (req, res) {
res.sendFile(path.join(__dirname, 'build', 'index.html'));
});
app.get('/logout', function (req, res) {
res.sendFile(path.join(__dirname, 'build', 'index.html'));
});
app.listen('8080');
console.log('Server started at port 8080');
Run Code Online (Sandbox Code Playgroud)
nginx 在重新启动后运行良好,但没有从我的域中删除端口号 8080。
要对端口执行哪些操作80?我刚刚从我的 AWS 实例入站规则中启用了 80,还有什么我错过的吗?
小智 5
您正在为域提供端口。
试试这样:
server {
server_name admin.example.com;
listen 80;
location / {
proxy_pass http://127.0.0.1:8081;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2550 次 |
| 最近记录: |