Nginx: Window下安装与配置

安装步骤

Nginx 的安装步骤比较简单,安装在windows上推荐使用压缩包的安装方式。压缩包安装方式配置属性更灵活。接下来是步骤:

步骤一

1.百度搜索Nginx,找到官网直接下载对应版本的压缩包。 有稳定版本和最新版本及以前版本,推荐使用稳定版本开发

下载地址:Nginx官方下载链接
Nginx: Window下安装与配置
2.下载完成之后,进行解压可以看到如下 文件结构。

Nginx: Window下安装与配置
3.双击nginx,exe 就启动了。在页面输入localhost。出现如下界面则表示安装成功。默认监听80端口号

Nginx: Window下安装与配置

4.liunx安装简单介绍

一、检查和安装依赖项

yum  -y install  gcc pcre pcre-devel  zlib zlib-devel openssl openssl-devel 如果没有会自动安装,有则不安装

二、下载liunx版本压缩包 ,解压之后找解压configure目录 使用 【./configure --prefix=自定义安装地址】配置安装目录

三、通过【make && make install 】 命令进行安装 安装成功之后的目录结构

Nginx: Window下安装与配置

四、【./nginx】- 启动 【./nginx -s stop】-关闭  【./nginx -s -reload】-重启

五、查看运行情况 【ps aux|grep nginx】 如下则启动成功

Nginx: Window下安装与配置

Nginx基本属性配置

1.找到安装目录下conf 文件下的nginx.conf文件 通过 Notepad++打开进行 属性配置

Nginx: Window下安装与配置

==>Nginx: Window下安装与配置

2.worker_processes  1;跟cpu数有关

3.events {

#nginx最大负载量 
    worker_connections 1024;
    }

4.include*       mime.types;*

Nginx: Window下安装与配置

5.server :http结构下可以有多个server。请求进来 确定 使用哪一个 server由 server_name 确定

Nginx: Window下安装与配置

6.location  :一个server下可以有多个location ,用来匹配 同一个域名下不同uri的访问

root 表示本地的根目录 ,可以写相对路径 也可以写绝对路径如 e:/nginx/html ;

index :访问主页 后面如果跟有多个页面  则会依次判断 如果第一个不存在 则向后匹配;

proxy_pass :转发  后跟系统地址

Nginx: Window下安装与配置

7.location匹配原则

Nginx: Window下安装与配置

Nginx: Window下安装与配置

Nginx: Window下安装与配置

Nginx的优化

1.worker_processes :工作进程

Nginx: Window下安装与配置

2.worker_cpu_affinity

Nginx: Window下安装与配置

3.worker_rlimit_nofile

Nginx: Window下安装与配置

4.events;

worker_connections:最大并发量;

maxClient:最大可用客户数;

epoll:非阻塞模型 ;

Nginx: Window下安装与配置

5.Http;

access_log :访问日志

error_log: 异常日志 ;

crit:错误级别;

Nginx: Window下安装与配置

6,缓存发送 请求

Nginx: Window下安装与配置

7.最大连接时间

Nginx: Window下安装与配置

8.内容压缩

Nginx: Window下安装与配置

**  9.静态文件缓存**

Nginx: Window下安装与配置

TIP:nginx启动关闭的命令 在nginx安装的目录下

开启 >nginx

关闭>nginx.exe -s stop