首页 新闻 会员 周边 捐助

CentOS修改nginx配置文件出错

0
悬赏园豆:50 [已解决问题] 解决于 2017-12-07 17:54
# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

events {
    worker_connections 1024;
}

http {
    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;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

    upstream 192.168.122.1{
        server 192.168.15.66:8081;
        server 192.168.15.66:8082;
        }
    server {
        listen       80;
        server_name  192.168.122.1;
        root         /usr/share/nginx/html;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
                proxy_pass http://192.168.122.1;
        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
                                                                                                                                                                                                 
    }
}

新手在学习nginx , 在虚拟机CentOS 7 中配置nginx.
配置如上 :
  在默认配置文件的基础上添加 upstream 节点, 并且更改 server 节点下 listen , server_name , location 三个节点 , 其中 192.168.122.1 为nginx所在服务器ip , 192.168.15.66:8081 和 192.168.15.66:8082 为需要做负载均衡的服务器ip
  但配置完重启nginx后会报 "The page you are looking for is temporarily unavailable. Please try again later."
  请问需要怎么更改配置 ? 求助
TryerLee的主页 TryerLee | 初学一级 | 园豆:21
提问于:2016-08-24 12:56
< >
分享
最佳答案
0

upstream 192.168.122.1proxy_pass http://192.168.122.1中把IP地址改为名称试试

收获园豆:25
dudu | 高人七级 |园豆:30902 | 2016-08-24 13:28

嗯, 这个确实是一个问题, 但是改了之后出现访问 localhost 报404错误, 这个依然很费解

(回复太慢, 不好意思)

TryerLee | 园豆:21 (初学一级) | 2016-09-13 10:14
其他回答(1)
0

server name和proxy_pass配置为一样,不会死循环么?

收获园豆:25
幻天芒 | 园豆:37207 (高人七级) | 2016-08-24 14:21

我把 proxy_pass 和 upstream 改成统一的名称 myservice , server_name 改成 localhost 却报404错误了

(回复太慢, 不好意思)

支持(0) 反对(0) TryerLee | 园豆:21 (初学一级) | 2016-09-13 10:17

@Tryer: http://zyan.cc/post/306/ 参考一下。

支持(0) 反对(0) 幻天芒 | 园豆:37207 (高人七级) | 2016-09-13 10:28

@幻天芒: 好的, 多谢

支持(0) 反对(0) TryerLee | 园豆:21 (初学一级) | 2016-09-13 11:27
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册