我在 有一个应用程序192.168.101.120:8080
。现在我想通过 nginx 在 端口 上运行它80
。查看nginx.conf
:
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log;
#error_log /var/log/nginx/error.log notice;
#error_log /var/log/nginx/error.log info;
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;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
# Load config files from the /etc/nginx/conf.d directory
# The default server is in conf.d/default.conf
include /etc/nginx/conf.d/*.conf;
server {
listen 80;
server_name myserver.com;
location / {
root /some/public/folder;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://192.168.101.120:8080;
}
}
}
但是端口80
显示默认的 nginx 页面。我可以更改listen 80;
为listen 8081;
,一切都会正常。哪里出了问题?
答案1
您可能有一个 default.conf 或 nginx 正在加载的类似文件。
尝试这个
grep -r 80 /etc/nginx/*
如果我说的正确的话,那可能会给你一些提示。
答案2
您的server_name
定义与您使用的 URL 不匹配,因此您获取了错误的虚拟主机。请记住,当时http://www.myserver.com
不起作用。server_name
mysserver.com