Proxy nginx简单代理\传递到本地主机不工作
我正在尝试运行一个极简反向代理,并得出以下结论:Proxy nginx简单代理\传递到本地主机不工作,proxy,nginx,Proxy,Nginx,我正在尝试运行一个极简反向代理,并得出以下结论: events { worker_connections 4096; } http { server { listen 80; location / { proxy_pass http://127.0.0.1:3000/; } } } ` 但是,当我访问此服务器时,我得到的是标准的“欢迎使用nginx页面”,而不是来自运行在端
events {
worker_connections 4096;
}
http {
server {
listen 80;
location / {
proxy_pass http://127.0.0.1:3000/;
}
}
}
`
但是,当我访问此服务器时,我得到的是标准的“欢迎使用nginx页面”,而不是来自运行在端口3000上的服务器的响应
如果我ssh到机器并运行
curlhttp://127.0.0.1:3000/
,我得到了期望的结果(最终我在端口80上运行了该服务器,它工作得很好,所以我知道这与反向代理配置有关)。我遇到了完全相同的问题。我刚刚注释掉了nginx.conf文件中的一行:
include /etc/nginx/sites-enabled/*;
worker_processes 4;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
gzip on;
gzip_http_version 1.0;
gzip_comp_level 5;
gzip_proxied any;
gzip_vary off;
gzip_types text/plain text/css application/x-javascript text/xml application/xml application/rss+xml application/atom+xml text/javascript application/javascript application/json text/mathml;
gzip_min_length 1000;
gzip_disable "MSIE [1-6]\.";
server_names_hash_bucket_size 64;
types_hash_max_size 2048;
types_hash_bucket_size 64;
client_max_body_size 1024;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
包括/etc/nginx/sites enabled/*;
改为
#include /etc/nginx/sites-enabled/*;
#包括/etc/nginx/sites enabled/*;
通过回答解释Vijay的帖子,因为exchange不会让我发表评论
可能需要注释掉启用站点的目录,因为您使用的是标准nginx.conf文件。您将注意到该行已经在http指令中。如果使用的是标准配置,则在另一个http指令中重新定义http指令。您还可以更新站点文件,使其仅具有server指令而不具有http指令
标准ish nginx.conf文件:
include /etc/nginx/sites-enabled/*;
worker_processes 4;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
gzip on;
gzip_http_version 1.0;
gzip_comp_level 5;
gzip_proxied any;
gzip_vary off;
gzip_types text/plain text/css application/x-javascript text/xml application/xml application/rss+xml application/atom+xml text/javascript application/javascript application/json text/mathml;
gzip_min_length 1000;
gzip_disable "MSIE [1-6]\.";
server_names_hash_bucket_size 64;
types_hash_max_size 2048;
types_hash_bucket_size 64;
client_max_body_size 1024;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
启用站点内的可兼容站点文件示例:
server {
server_name {server name};
listen 80;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
location / {
proxy_pass http://example.com:8080;
proxy_set_header Host $host;
}
}
检查从启用的站点到可用站点的链接也可能有所帮助。
我的符号链接指向别处,因此nginx从未读取配置。
在我的情况下是这样的
ls -lh /etc/nginx/sites-enabled
lrwxrwxrwx 1 root root 23 Feb 19 11:11 default -> sites-available/default
而不是
ls -lh /etc/nginx/sites-enabled
lrwxrwxrwx 1 root root 23 Feb 19 11:11 default -> ../sites-available/default
我的注释包括/etc/nginx/conf.d/*.conf
# inculude /etc/nginx/conf.d/*.conf
里面装的是
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
在我的例子中,我总是得到默认的nginx页面。事实证明,问题在于一些工具(我假设让我们加密/Certbot)在sites enabled/default
中添加了一些条目,这些条目重写了我的sites enabled/mysite.com
中的条目
删除站点启用/default
中的条目解决了问题。相同的配置在我的devbox上运行良好。您的web服务器的网络似乎有问题。您是否尝试重新启动网络?是否确定在另一个conf文件中没有其他代理指令?proxy.conf?删除后面的斜杠有什么作用吗?是的,我尝试了使用斜杠和不使用斜杠。。。将重新启动并重试。我花了4个小时试图解决此问题,然后我才开始清理MC编辑器中的空间选项卡并开始工作*******你说的不管用。我没有启用任何include/etc/nginx/sites/*代码>nginx文件夹中的任意位置,并体验您所说的不起作用的问题。我没有启用任何include/etc/nginx/sites/*
注释/etc/nginx
文件夹中的任何位置,或配置静止并体验issue@Green有点晚了,但我自己刚刚遇到这个问题。我案例中的include文件是/etc/nginx/conf.d/*.conf
——这包括与我的站点配置冲突的默认站点的配置。在您的情况下,可能是代理配置本身有问题,并且注释了包括/etc/nginx/conf.d/*.conf
帮助。但是目录/etc/nginx/conf.d
是空的。为什么这项工作如此不可预测?谢谢。。我在使用nginx在树莓pi上建立ha桥时遇到了问题。这确实有助于meI注释掉这个文件,但保留站点启用
行不变,因为它指向站点可用/default.conf
文件,在该文件中,我进行了最初不起作用的更改。