pm2 / nginx.conf
jimlv's picture
Update nginx.conf
b32de9a verified
Raw History Blame Contribute Delete
2.11 kB
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
keepalive_timeout 65;
server {
listen 7860;
# --- 新增配置:处理根路径 / 的请求 ---
location / {
# 返回一个简单的HTML页面
return 200 '<!DOCTYPE html>
<html>
<head>
<title>My Node.js Services</title>
<style>
body { font-family: sans-serif; text-align: center; padding: 50px; }
a { display: inline-block; margin: 20px; padding: 10px 20px; background: #007bff; color: white; text-decoration: none; border-radius: 5px; }
a:hover { background: #0056b3; }
</style>
</head>
<body>
<h1>Welcome to My Node.js Services</h1>
<p>Choose a service to access:</p>
<div>
<a href="/app1/">Go to App 1</a>
<a href="/app2/">Go to App 2</a>
<a href="/app3/">Go to App 3</a>
</div>
</body>
</html>';
# 指定返回内容的类型
add_header Content-Type text/html;
}
# -----------------------------------
location /app1/ {
proxy_pass http://127.0.0.1:3001/;
proxy_set_header Host $host;
}
location /app2/ {
proxy_pass http://127.0.0.1:3002/;
proxy_set_header Host $host;
}
location /app3/ {
proxy_pass http://127.0.0.1:3003/;
proxy_set_header Host $host;
}
}
}