# 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."
请问需要怎么更改配置 ? 求助
upstream 192.168.122.1与proxy_pass http://192.168.122.1中把IP地址改为名称试试
嗯, 这个确实是一个问题, 但是改了之后出现访问 localhost 报404错误, 这个依然很费解
(回复太慢, 不好意思)
server name和proxy_pass配置为一样,不会死循环么?
我把 proxy_pass 和 upstream 改成统一的名称 myservice , server_name 改成 localhost 却报404错误了
(回复太慢, 不好意思)
@Tryer: http://zyan.cc/post/306/ 参考一下。
@幻天芒: 好的, 多谢