侧边栏壁纸
博主头像
落叶人生博主等级

走进秋风,寻找秋天的落叶

  • 累计撰写 130562 篇文章
  • 累计创建 28 个标签
  • 累计收到 9 条评论
标签搜索

目 录CONTENT

文章目录

nginx配置初试

2023-11-15 星期三 / 0 评论 / 0 点赞 / 56 阅读 / 9938 字

下载http://nginx.org/,windowns版,解压即可 启动nginx.exe,默认访问http://localhost,出现Welcome to nginx!,表示安装成功。

  1. 下载http://nginx.org/,windowns版,解压即可
  2. 启动nginx.exe,默认访问http://localhost,出现Welcome to nginx!,表示安装成功。
    1. 失败原因:端口占用,cmd:netstat -ano |find 80。查看80端口是否占用。
    2. 到安装目录打开cmd(按住shift,右键,在此处打开命令行),查看nginx -s reopen,检查nginx.config配置是否正确。第一次安装一般不会有此问题。
    3. 命令nginx -s reload 重新加载配置,修改nginx.config后运行;nginx -s stop 停止
  3. 配置解析
    1. user  nobody;
      # 使用的用户和组  运行用户
        
      #user  linshi;
      # 指定工作进程数 启动进程,通常设置成和cpu的数量相等 
      worker_processes  1;
      #全局错误日志
      #error_log  logs/error.log;
      #error_log  logs/error.log  notice;
      #error_log  logs/error.log  info;
      # 指定 pid 存放的路径  PID文件,记录当前启动的nginx的进程ID
      #pid        logs/nginx.pid;

      #-----------------------------------事件模块   工作模式及连接数上限
      events {
      #每个worker的最大连接数 #单个后台worker process进程的最大并发链接数
          worker_connections  1024;
      }

    2. http {
             #包含一个文件描述了:不同文件后缀对应的MIME,见案例分析  
          include       mime.types;
          #制定默认MIME类型为二进制字节流  
          default_type  application/octet-stream;

          #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 指派路径、格式和缓存大小。 

          #access_log  off;  
          #access_log  logs/access.log  main;
      #开启调用<a href="http://lib.csdn.net/base/linux" class='replace_word' title="Linux知识库" target='_blank' style='color:#df3434; font-weight:bold;'>Linux</a>的sendfile(),提供文件传输效率  
          sendfile        on;
          #是否允许使用socket的TCP_NOPUSH或TCP_CORK选项 
          #tcp_nopush     on;
      #指定客户端连接保持活动的超时时间,在这个时间之后,服务器会关掉连接。
          #keepalive_timeout  0;
          keepalive_timeout  65;
      #设置gzip,压缩文件  
          #gzip  on;
      #为后端服务器提供简单的负载均衡  
        负载方式:1. 加权轮询(weighted round robin),down为停止使用,backup为备份2.不加权重,方式    fair,hash,ip hash(可解决session问题)有
      upstream apaches {   
          server 127.0.0.1:8888;   
          server 127.0.0.1:8088 down;    
          server 127.0.0.1:8889 weight=3;    
          server 127.0.0.1:8888 backup;  
        
      }  


              
       upstream iis_server{
          server localhost:8888;
         }

        
          server {
              listen       80;
              server_name  localhost; 
              #charset koi8-r;

              #access_log  logs/host.access.log  main;
          #默认指向product的server
              location / {
                root   html;
               index  index.html index.htm;
          #proxy_pass http://apaches; 此处为负载配置方式
          proxy_connect_timeout 600;
              proxy_read_timeout 600;
       
              } 
              #配置分布式,如果只有一台应用,忽略此配置。设置每一个业务对应一台业务主机。此处直接加test_server默认把/test/的目录加在目录上出现404,所有采用加一个无用的目录,再返回的方法解决。###此处写法对于强迫症患者有成吨的伤害,请有解决方法的兄弟,留下宝贵意见。###
          location /test/ {proxy_connect_timeout 600;
              proxy_read_timeout 600;
              proxy_pass http://localhost:8889/root/../;
          }

          location /iis/ {
             proxy_connect_timeout 600;
              proxy_read_timeout 600;
              proxy_pass http://iis_server/root/../;
          }
              
                 
           
           #设定查看Nginx状态的地址
              location /NginxStatus {
                  stub_status           on;
                  access_log            on;
                  auth_basic            "NginxStatus";
                  auth_basic_user_file  ../htpasswd;
              }
          
              #禁止访问 .htxxx 文件
              #location ~ //.ht {
              #    deny all;
              #}

              #error_page  404              /404.html;

              # redirect server error pages to the static page /50x.html
              #
              error_page   500 502 503 504  /50x.html;
              location = /50x.html {
                  root   html;
              }

              # proxy the PHP scripts to Apache listening on 127.0.0.1:80
              #
              #location ~ /.php$ {
              #    proxy_pass   http://127.0.0.1;
              #}

              # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
              #
              #location ~ /.php$ {
              #    root           html;
              #    fastcgi_pass   127.0.0.1:9000;
              #    fastcgi_index  index.php;
              #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
              #    include        fastcgi_params;
              #}

              # deny access to .htaccess files, if Apache's document root
              # concurs with nginx's one
              #
              #location ~ //.ht {
              #    deny  all;
              #}

          #通过手机客户端的头信息或者请求的参数转发到不用目录
          
          #防盗链
          
          }

    3.   https配置暂时没弄# another virtual host using mix of IP-, name-, and port-based configuration
          #
          #server {
          #    listen       8000;
          #    listen       somename:8080;
          #    server_name  somename  alias  another.alias;

          #    location / {
          #        root   html;
          #        index  index.html index.htm;
          #    }
          #}


          # HTTPS server
          #
          #server {
          #    listen       443 ssl;
          #    server_name  localhost;

          #    ssl_certificate      cert.pem;
          #    ssl_certificate_key  cert.key;

          #    ssl_session_cache    shared:SSL:1m;
          #    ssl_session_timeout  5m;

          #    ssl_ciphers  HIGH:!aNULL:!MD5;
          #    ssl_prefer_server_ciphers  on;

          #    location / {
          #        root   html;
          #        index  index.html index.htm;
          #    }
          #}

 

广告 广告

评论区