ngnix windows

本文介绍如何在Windows环境下安装Nginx,并提供了详细的步骤指导。此外,还列举了Nginx Windows版的一些已知问题及可能的未来改进方向。
Version of nginx for Windows uses the native Win32 API (not the Cygwin emulation layer). Only the select() connection processing method is currently used, so high performance and scalability should not be expected. Due to this and some other known issues version of nginx for Windows is considered to be a beta version. At this time, it provides almost the same functionality as a UNIX version of nginx except for XSLT filter, image filter, GeoIP module, and embedded Perl language.

To install nginx/Windows, download the latest mainline version distribution (1.9.6), since the mainline branch of nginx contains all known fixes. Then unpack the distribution, go to the nginx-1.9.6 directory, and run nginx. Here is an example for the drive C: root directory:

cd c:\
unzip nginx-1.9.6.zip
cd nginx-1.9.6
start nginx
Run the tasklist command-line utility to see nginx processes:

C:\nginx-1.9.6>tasklist /fi "imagename eq nginx.exe"

Image Name           PID Session Name     Session#    Mem Usage
=============== ======== ============== ========== ============
nginx.exe            652 Console                 0      2 780 K
nginx.exe           1332 Console                 0      3 112 K
One of the processes is the master process and another is the worker process. If nginx does not start, look for the reason in the error log file logs\error.log. If the log file has not been created, the reason for this should be reported in the Windows Event Log. If an error page is displayed instead of the expected page, also look for the reason in the logs\error.log file.

nginx/Windows uses the directory where it has been run as the prefix for relative paths in the configuration. In the example above, the prefix is C:\nginx-1.9.6\. Paths in a configuration file must be specified in UNIX-style using forward slashes:

access_log   logs/site.log;
root         C:/web/html;
nginx/Windows runs as a standard console application (not a service), and it can be managed using the following commands:

nginx -s stop	fast shutdown
nginx -s quit	graceful shutdown
nginx -s reload	changing configuration, starting new worker processes with a new configuration, graceful shutdown of old worker processes
nginx -s reopen	re-opening log files
Known issues

Although several workers can be started, only one of them actually does any work.
A worker can handle no more than 1024 simultaneous connections.
The cache and other modules which require shared memory support do not work on Windows Vista and later versions due to address space layout randomization being enabled in these Windows versions.
Possible future enhancements

Running as a service.
Using the I/O completion ports as a connection processing method.
Using multiple worker threads inside a single worker process.

转载于:https://my.oschina.net/yaolifei/blog/523457

### 如何在 Windows 上安装和配置 Nginx #### 一、Nginx 下载 为了获取最新的稳定版本,建议访问官方网站进行下载[^1]。 ```bash https://nginx.org/en/download.html ``` 选择适合 Windows 的压缩包并下载到本地计算机。解压文件至指定路径,例如 `C:\nginx`。 #### 二、Nginx 安装 实际上,在 Windows 平台上部署 Nginx 不涉及传统意义上的“安装”,而是简单地将官方发布的 ZIP 文件夹放置于任意位置即可完成初步设置工作。 #### 三、配置 进入解压后的目录找到 `conf/nginx.conf` 文件,这是主要的配置文档。对于初次使用者来说,默认配置已经能够满足大部分需求;如果有特殊要求,则可以根据实际情况修改此文件中的参数设定。 #### 四、验证 打开命令提示符(CMD),切换到 nginx 所在目录下执行如下指令启动服务: ```bash start nginx ``` 此时应该可以在浏览器地址栏输入 `http://localhost/` 访问默认欢迎页面以确认安装成功。 关于停止 Nginx 运行需要注意的是,即使通过 CMD 启动也不必担心关闭窗口会终止其运作。要正常退出程序有两种方法可供选择:一种是在同一级目录内运行 `nginx -s stop`; 另外还可以利用任务管理器查找名为 “nginx.exe” 的进程手动结束它们[^2]。 #### 五、其它问题 ##### 1. 常用命令 除了上述提到的服务控制之外,还有一些常用的维护操作可以帮助更好地管理和优化 Nginx 性能表现。比如重新加载配置而无需重启整个服务器可以通过下面这条语句实现: ```bash nginx -s reload ``` ##### 2. 跨域问题 当遇到跨源资源共享(CORS)难题时,可在 HTTP 或 server 模块里加入相应的头部信息来解决这类权限冲突情况。具体做法是在 `nginx.conf` 中添加类似这样的字段: ```nginx add_header 'Access-Control-Allow-Origin' '*'; add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值