Linux下nginx相关配置

公司服务器项目使用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了,挺搓的我,哈哈。。。

4、第一次接触nginx,参考的资料:nginx中文文档  nginx官网

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值