请问下在linux环境下 goblog.com 需要加端口是怎么回事?

系统版本 centos-stream
127.0.0.1 localhost 均跳转到 nginx展示页

需要加上 :3000 才能访问。 下面是配置代码 请问我是哪里没有配置对吗?

server {
    listen       80;
       server_name goblog.com;

    location / {
        proxy_pass                 http://127.0.0.1:3000;
        proxy_redirect             off;
        proxy_set_header           Host             $host;
        proxy_set_header           X-Real-IP        $remote_addr;
        proxy_set_header           X-Forwarded-For  $proxy_add_x_forwarded_for;
    }
}
任飘渺
最佳答案

这是查看端口和nginx展示的图片。

file

file

nginx 完整配置文件:

#user  nobody;
worker_processes  1;
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
include       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  logs/access.log  main;

sendfile        on;
#tcp_nopush     on;

#keepalive_timeout  0;
keepalive_timeout  65;

#gzip  on;

server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
    include /etc/nginx/sites-enabled/*.conf;
}

这个是 goblog.com 配置

Go

Go

hosts文件

Go

刚刚又测试了一下

Go

在nginx日志看到这一条

22/03/22 17:45:31 [crit] 8802#8802: *4 connect() to 127.0.0.1:3000 failed (13: Permission denied) while connecting to upstream, client: 127.0.0.1, server: goblog.com, request: “GET /favicon.ico HTTP/1.1”, upstream: “http://127.0.0.1:3000/favicon.ico", host: “goblog.com”, referrer: “http://goblog.com/"

2022/03/22 17:45:31 [crit] 8802#8802: *7 connect() to 127.0.0.1:3000 failed (13: Permission denied) while connecting to upstream, client: 127.0.0.1, server: goblog.com, request: “GET / HTTP/1.1”, upstream: “http://127.0.0.1:3000/", host: “goblog.com”

2022/03/22 17:45:31 [crit] 8802#8802: *7 connect() to 127.0.0.1:3000 failed (13: Permission denied) while connecting to upstream, client: 127.0.0.1, server: goblog.com, request: “GET /favicon.ico HTTP/1.1”, upstream: “http://127.0.0.1:3000/favicon.ico", host: “goblog.com”, referrer: “http://goblog.com/"

2022/03/22 17:46:20 [crit] 8802#8802: *7 connect() to 127.0.0.1:3000 failed (13: Permission denied) while connecting to upstream, client: 127.0.0.1, server: goblog.com, request: “GET / HTTP/1.1”, upstream: “http://127.0.0.1:3000/", host: “goblog.com”

百度发现 SeLinux 的权限策略所致

setsebool -P httpd_can_network_connect 1

2年前 评论
讨论数量: 4
Summer

centos-stream 没用过。

检查 80 端口是否是被 Nginx 使用,有些时候系统会默认启用 httpd(Apache),也是占用了 80 端口。

2年前 评论
任飘渺

如果 80 端口被占用 nginx应该开启不了才是,目前可以访问到 nginx默认页面

这里我还有一个疑问:

nginx 默认配置是这种形式的

include /etc/nginx/conf.d/*.conf; 文件形式是:goblog.com.conf

include /etc/nginx/sites-enabled/*; goblog.com

2年前 评论
Summer

吃过多次亏,你这个页面看不出来是 nginx 界面,要确定一下:

netstat -nlp | grep 80

配置问题的话,自己调试一下,手头上没有 centos-stream ,不知道默认安装的配置是咋样的。

2年前 评论
任飘渺

这是查看端口和nginx展示的图片。

file

file

nginx 完整配置文件:

#user  nobody;
worker_processes  1;
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
include       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  logs/access.log  main;

sendfile        on;
#tcp_nopush     on;

#keepalive_timeout  0;
keepalive_timeout  65;

#gzip  on;

server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
    include /etc/nginx/sites-enabled/*.conf;
}

这个是 goblog.com 配置

Go

Go

hosts文件

Go

刚刚又测试了一下

Go

在nginx日志看到这一条

22/03/22 17:45:31 [crit] 8802#8802: *4 connect() to 127.0.0.1:3000 failed (13: Permission denied) while connecting to upstream, client: 127.0.0.1, server: goblog.com, request: “GET /favicon.ico HTTP/1.1”, upstream: “http://127.0.0.1:3000/favicon.ico", host: “goblog.com”, referrer: “http://goblog.com/"

2022/03/22 17:45:31 [crit] 8802#8802: *7 connect() to 127.0.0.1:3000 failed (13: Permission denied) while connecting to upstream, client: 127.0.0.1, server: goblog.com, request: “GET / HTTP/1.1”, upstream: “http://127.0.0.1:3000/", host: “goblog.com”

2022/03/22 17:45:31 [crit] 8802#8802: *7 connect() to 127.0.0.1:3000 failed (13: Permission denied) while connecting to upstream, client: 127.0.0.1, server: goblog.com, request: “GET /favicon.ico HTTP/1.1”, upstream: “http://127.0.0.1:3000/favicon.ico", host: “goblog.com”, referrer: “http://goblog.com/"

2022/03/22 17:46:20 [crit] 8802#8802: *7 connect() to 127.0.0.1:3000 failed (13: Permission denied) while connecting to upstream, client: 127.0.0.1, server: goblog.com, request: “GET / HTTP/1.1”, upstream: “http://127.0.0.1:3000/", host: “goblog.com”

百度发现 SeLinux 的权限策略所致

setsebool -P httpd_can_network_connect 1

2年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!