Window使用nginx

2022-08-01 13:58:43

Window使用nginx



前言

Nginx是一款轻量级web服务器、也是一款反向代理服务器

Nginx的功能

     (1)可直接支持Rails和PHP的程序

     (2)可以作为HTTP的反向代理服务器

     (3)可作为负载均衡服务器

     (4)可作为邮件代理服务器

     (5)帮助实现前端动静分离

————————————————
Nginx的特点

    1、 高稳定、高性能、资源占用少

     2、功能丰富、模块化结构、支持热部署

一、下载nginx

下载路径:http://www.nginx.org/
解压后如下:
在这里插入图片描述

二、Nginx配置

配置文件在 conf 目录里的 nginx.conf 文件

1.配置信息如下

配置文件如下(示例):

#usernobody;//指定nginx进程数
worker_processes1;//全局错误日志及PID文件#error_log  logs/error.log;#error_log  logs/error.log  notice;#error_log  logs/error.log  info;#pidlogs/nginx.pid;


events{// 连接数上限
    worker_connections1024;}//设定http服务器,利用它的反向代理功能提供负载均衡支持

http{//设定mime类型,类型由mime.type文件定义
    include       mime.types;
    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  logs/access.log  main;//sendfile 指令指定 nginx 是否调用 sendfile 函数(zero copy 方式)来输出文件,对于普通应用
    sendfile        on;#tcp_nopush     on;//连接超时时间#keepalive_timeout0;
    keepalive_timeout65;//开启gzip压缩 ,压缩html#gzipon;//设定负载均衡的服务器列表 支持多组的负载均衡,可以配置多个upstream  来服务于不同的Server.
	upstream Jq_one{//weigth参数表示权值,权值越高被分配到的几率越大//down 表示单前的server暂时不参与负载//weight 默认为1.weight越大,负载的权重就越大。//backup: 其它所有的非backup机器down或者忙的时候,请求backup机器。所以这台机器压力会最轻。
      
 	 server127.0.0.1:44397 weight=2;
 
 	 server127.0.0.1:44315 weight=4;}//配置代理服务器的地址,即Nginx安装的服务器地址、监听端口、默认地址
    server{//侦听8456端口
        listen8456;//对于server_name,如果需要将多个域名的请求进行反向代理,可以配置多个server_name来满足要
        server_name  localhost;#charsetkoi8-r;#access_log  logs/host.access.log  main;
	
        location/{//默认主页目录在nginx安装目录的html子目录。
        	 root   html;
            indexdefault.aspx;
            proxy_pass https://Jq_one;
             proxy_set_header Host $host;//跟载均衡服务器的upstream对应}#error_page404/404.html;#redirectserver error pages to thestatic page/50x.html#error_page500502503504/50x.html;
        location=/50x.html{
            root   html;}#proxythe PHP scripts to Apache listening on127.0.0.1:80
        ##location~ \.php${#proxy_pass   http://127.0.0.1;
        #}#passthe PHP scripts to FastCGI server listening on127.0.0.1:9000
        ##location~ \.php${#roothtml;#fastcgi_pass127.0.0.1:9000;#fastcgi_index  index.php;#fastcgi_param  SCRIPT_FILENAME/scripts$fastcgi_script_name;#includefastcgi_params;
        #}#denyaccess to.htaccess files,if Apache's document root#concurswith nginx's one
        ##location~/\.ht{#denyall;
        #}}#anothervirtual host using mix of IP-, name-, and port-based configuration
    ##server{#listen8000;#listensomename:8080;#server_name  somename  alias  another.alias;#location/{#roothtml;#indexindex.html index.htm;
    #}
    #}#HTTPS server
    ##server{#listen443 ssl;#server_name  localhost;#ssl_certificate      cert.pem;#ssl_certificate_key  cert.key;#ssl_session_cache    shared:SSL:1m;#ssl_session_timeout5m;#ssl_ciphers  HIGH:!aNULL:!MD5;#ssl_prefer_server_ciphers  on;#location/{#roothtml;#indexindex.html index.htm;
    #}
    #}}

2.启动Nginx

命令如下(示例):

	 D:\Program\nginx-1.9.3> start nginx  //启动nginx	
	 D:\Program\nginx-1.9.3> nginx.exe -s stop  //停止nginx
   	 D:\Program\nginx-1.9.3> nginx.exe -s reload  //重启nginx

总结

人们应该庆幸不知道何时离开这个世界,这样才能让他们心安的沉迷眼前的纸醉金迷。

  • 作者:疯狂Programmer
  • 原文链接:https://blog.csdn.net/qq_42455262/article/details/123787086
    更新时间:2022-08-01 13:58:43