window下安装nginx

来源:互联网 发布:振芯科技 人工智能 编辑:程序博客网 时间:2024/05/22 03:18

1 nginx简介

1.1 什么是nginx

Nginx是一款高性能的http服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器。由俄罗斯的程序设计师Igor Sysoev所开发官方测试nginx能够支支撑5万并发链接,并且cpu、内存等资源消耗却非常低,运行非常稳定。


1.2 Nginx的应用场景

1、http服务器。Nginx是一个http服务可以独立提供http服务。可以做网页静态服务器。

2、虚拟主机。可以实现在一台服务器虚拟出多个网站。例如个人网站使用的虚拟主机。

3、反向代理,负载均衡。当网站的访问量达到一定程度后,单台服务器不能满足用户的请求时,需要用多台服务器集群可以使用nginx做反向代理。并且多台服务器可以平均分担负载,不会因为某台服务器负载高宕机而某台服务器闲置的情况。

2 nginx安装


2.1 下载nginx


2.2 解压,

2.3 进入解压目录,nginx.exe是nginx启动程序, conf是nginx一些配置文件目录, 其中conf下的nginx.conf是nginx主配置文件


2.4 编辑主配置文件nginx.conf 

可根据需要进行编辑,也可以保持默认

系统默认的配置如下:

#user  nobody;worker_processes  1;#error_log  logs/error.log;#error_log  logs/error.log  notice;#error_log  logs/error.log  info;#pid        logs/nginx.pid;events {    worker_connections  1024;}http {    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        on;    #tcp_nopush     on;    #keepalive_timeout  0;    keepalive_timeout  65;    #gzip  on;    server {        listen       80;        server_name  localhost;        #charset koi8-r;        #access_log  logs/host.access.log  main;        location / {            root   html;            index  index.html index.htm;        }        #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;        #}    }    # 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;    #    }    #}}

2.5 切换到nginx.exe所在目录下, cmd打开命令行窗口 输入 nginx -t

若出现OK和successful字样,则说明配置成功

2.6 修改配置后重新加载nginx使生效,  nginx -s reload

nginx -v  可查看nginx版本


地址栏输入 127.0.0.1 ,如出现如下提示,则说明nginx启动成功.



启动nginx的时候, 窗口闪了一下,属于正常情况,因为nginx没有界面.


nginx的几个主要命令

查看nginx版本号: nginx -v

启动服务:start nginx

快速停止或关闭服务: nginx -s stop

正常停止或关闭服务: nginx -s quit

配置文件修改重新加载命令: nginx -s reload

查看windows任务管理器下nginx的进程命令: tasklist /fi "imagename eq nginx.exe"



使用页面静态化模板生成的静态化文件就可以放在nginx上

Writer out =new FileWriter(new File("F:\\nginx-1.8.0\\html\\"+borrowmoney2.getBid()+".html"));template.process(values, out);