公司服务器项目使用nginx做转发及负载均衡,在这期间遇到一些,尤其是404问题,下面就说说我的nginx配置,以及我对404的解决。
我这里用了两个配置文件
1、nginx.conf配置文件
#user nobody;
worker_processes 1;
#pid logs/nginx.pid;
error_log /var/log/nginx/error.log;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#access_log logs/access.log main;
port_in_redirect off ;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
# redirect server error pages to the static page /50x.html
#
#error_page 500 502 503 504 /50x.html;
#location = /50x.html {
# root html;
#}
include /usr/local/nginx/conf/conf.d/*.conf;
client_max_body_size 32M;
client_body_buffer_size 1024k;
}
2、在conf.d文件夹下新建了一个文件oa.conf
#upstream t {
# server 192.168.7.176:8888;
#server 127.0.0.1:8888;
#}
server
{
listen 80;
server_name t.test.minisocials.com;
location / {
real_ip_header X-Real-IP;
# proxy_pass http://t;
proxy_pass http://192.168.7.176:8888;
access_log /usr/local/nginx/t.log;
}
}
注:upstream用于做负载均衡,由于我的是测试服务器就不需要做负载均衡,故内容注释
3、现在说说404的问题
当初公司测试服务器nginx不知道是谁安装的,nginx.conf有两个配置文件,一个在/etc/nginx/nginx.conf,另一个在/usr/local/nginx/conf/nginx.conf,然后我修改的是/usr路径下的配置文件,导致修改过的内容一直报错404,后来通过nginx -t命令使配置文件生效,看到了生效的配置文件路径是/etc下的配置文件,才发现原来我之前改的位置不对,然后将我改的配置文件替换了/etc路径下的配置文件,就ok了,没有出现404了,挺搓的我,哈哈。。。