设为首页 加入收藏

TOP

Nginx在windows环境下的安装与简单配置(一)
2019-09-17 18:42:09 】 浏览:38
Tags:Nginx windows 环境 安装 简单 配置

版权声明:本文为博主原创文章,未经博主允许不得转载。

一. 下载并安装Nginx

Nginx官网下载

我这里选取nginx/Windows-1.10.3版本,下载后解压出来即可,解压出来的路径不能含有中文

我解压后将其放置的路径如下

 

 二、开始运行

在当前目录下按住shift+鼠标右键,选择“在此处打开命令窗口”,然后输入start nginx

此时,就可以进入浏览器输入访问地址,http://127.0.0.1/或者http://localhost/即可访问

三、配置文件讲解

核心配置文件就是nginx.conf,该文件位于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;
    #    }
    #}

}

  

 其中#代表注释

nginx我们最主要的作用是拿来做反向代理和负载均衡,这个我后面会着重讲解。同时它还是一个web服务器,与我们常用的Apache、tomcat、IIS一样,也可以用来托管web服务。

本章先暂时介绍下该配置文件中的几个重要参数,后面会对nginx部署php和Python项目再进行着重讲解,至于java的项目通常是tomcat+nginx同时进行配置,nginx用来做负载均衡和处理静态页。

1、定义Nginx运行的用户和用户组

#user  nobody;

2、nginx进程数,建议设置为等于CPU总核心数

worker_processes 1;

3、全局错误日志定义类型,[ debug | info | notice | warn | error | crit ]

#error_log logs/error.log notice;
#error_log logs/error.log info;

4、进程文件

#pid        logs/nginx.pid;

5、工作模式与连接数上限:worker_connections是单个后台worker process进程的最大并发链接数,并发总数是 worker_processes 和 worker_connections 的乘积, 即 max_clients = worker_processes * worker_connections

events {
worker_connections 1024;
}

6、http下的一些配置及其意义

include mime.types; #文件扩展名与文件类型映射表
default_type application/octet-stream; #默认文件类型
sendfile on; #开启高效文件传输模式,sendfile指令指定ngin
首页 上一页 1 2 下一页 尾页 1/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇面向对象构造与设计第一次总结 下一篇Ehcache入门经典:第二篇ehcache...

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目