一个关于nginx的配置问题 5C

listen 0.0.0.0:80;
40 server_name localhost;
41
42 #charset koi8-r;
43
44 #access_log logs/host.access.log main;
45
46 location / {
47 #root html;
48 #index index.html index.htm;
49 proxy_pass http://127.0.0.1:8000;
50 proxy_set_header Host $host;
51 proxy_set_header X-Real-IP $remote_addr;

这段代码有错吗?为什么我nginx开启之后访问不了?

0

3个回答

使用nginx -t 命令 检查语法是否正确

0

http://127.0.0.1:8000;
z这个端口有没有程序侦听,

查看一下nginx的error.log里面会有比较具体的错误信息

0

nginx的用途很多,功能也很多。看你这一段的配置,感觉你像是使用命令安装的nginx,而且nginx工作是一个代理转发的状态:
1、nginx监听本机所有IP的80端口
2、将访问http://ip/地址转发到http://127.0.0.1:8000/服务上,并且将该请求的原ip写到header中

不通的原因可能有:
1、代理转发的服务http://127.0.0.1:8000这个是否可能访问?

我给一个nginx作为web服务器的配置:

user root root;

worker_processes  8;

error_log /usr/local/nginx/logs/error.log info;

pid     /usr/local/nginx/nginx.pid;

worker_rlimit_nofile 65535;

events {
        use epoll;
        worker_connections  65535;
}

http {
        include       mime.types;
        default_type  application/octet-stream;
        sendfile        on;
        tcp_nopush      on;
        gzip            on;

        keepalive_timeout 30;
        keepalive_requests 10;

        client_header_buffer_size 4k;

        open_file_cache max=65535 inactive=60s;
        open_file_cache_valid 80s;
        open_file_cache_min_uses 1;
        open_file_cache_errors on;

        server {
                listen       80;
                server_name  lyf-test;

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

}

再给一个nginx作为负载均衡的配置(nginx使用阿里的tenginx):

user root root;

worker_processes  8;

error_log /usr/local/nginx/logs/error.log info;

pid     /usr/local/nginx/nginx.pid;

worker_rlimit_nofile 65535;

events {
        use epoll;
        worker_connections  65535;
}

http {
        include       mime.types;
        default_type  application/octet-stream;
        sendfile        on;
        tcp_nopush      on;
        gzip            on;
        keepalive_timeout 30;
        keepalive_requests 10;
        client_header_buffer_size 4k;

        open_file_cache max=65535 inactive=60s;
        open_file_cache_valid 80s;
        open_file_cache_min_uses 1;
        open_file_cache_errors on;

        upstream testLB {
                server 192.168.40.4:101;
                server 192.168.40.4:102;
                server 192.168.40.4:103;
        }

        server {
                listen       80;
                server_name  lyf-test-http;

                location / {
                        limit_req zone=ips burst=5 nodelay;

                        root   html;
                        index  index.html;
                        proxy_pass http://testLB;
                }
                location /nginx/monitor {
                        stub_status on;
                }
        }
}
0
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!