widows下nignx的使用

  nignx在Linux环境下可以大展身手,在widows环境下也可以启动一定的效果,但是没有linux用的好。

Nginx (engine x) 是一款轻量级的Web 服务器 、反向代理服务器及电子邮件(IMAP/POP3)代理服务器。

什么是反向代理?

反向代理(Reverse Proxy)方式是指以代理服务器来接受internet上的连接请求,然后将请求转发给内部网络上的服务器,并将从服务器上得到的结果返回给internet上请求连接的客户端,此时代理服务器对外就表现为一个反向代理服务器。

具体项目的配置

  1 #user  nobody;
  2 
  3 worker_processes  4;
  4 
  5 #error_log  logs/error.log;
  6 
  7 #error_log  logs/error.log  notice;
  8 
  9 #error_log  logs/error.log  info;
 10 
 11 #pid        logs/nginx.pid;
 12 
 13 #worker_rlimit_nofile 65535; 
 14 
 15 events {
 16 
 17     worker_connections  65535;
 18 
 19  } 
 20 
 21 http  {
 22 
 23     include       mime.types;
 24 
 25     default_type  application/octet-stream;
 26 
 27     include domains/*;
 28 
 29     map $http_upgrade $connection_upgrade {
 30         default upgrade;
 31         ''      close;
 32     }
 33 
 34 
 35     sendfile        on;
 36 
 37     keepalive_timeout  60;
 38     client_header_buffer_size 8k;
 39     large_client_header_buffers 4 8k;
 40 
 41     upstream tomcat {
 42 
 43         #server 192.168.203.48:8011 max_fails=1 fail_timeout=10s;
 44         server 127.0.0.1:8086 max_fails=1 fail_timeout=10s;
 45 
 46      } 
 47 
 48     server  {
 49 
 50         #listen       8012 backlog=20480;
 51         listen       8012;
 52 
 53         server_name  localhost;
 54         client_body_buffer_size  1024k;
 55         
 56              
 57           # set site favicon  
 58             location /favicon.ico {  
 59                 root html;  
 60             }  
 61 
 62         location ~/(companylogo|shoppingMallImage|wwzzImage)/{
 63 
 64              root D:\upload;
 65 
 66          }
 67         
 68          location ~ .(js|css|png|jpg|jpeg|ico|xml|swz|svg)$ {  
 69 
 70             root ../tomcat/webapps/; 
 71             
 72          }  
 73 
 74         location / {
 75 
 76             proxy_set_header X-Real-IP $remote_addr;
 77 
 78             proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 79 
 80             proxy_next_upstream error timeout invalid_header;
 81 
 82             proxy_connect_timeout 60s;
 83 
 84             proxy_read_timeout 60s;
 85 
 86             proxy_send_timeout 60s;
 87 
 88             proxy_buffer_size 4k; #设置代理服务器(nginx)保存用户头信息的缓冲区大小
 89             proxy_buffers 4 32k; #proxy_buffers缓冲区,网页平均在32k以下的设置
 90             proxy_busy_buffers_size 64k; #高负荷下缓冲大小(proxy_buffers*2)
 91             proxy_temp_file_write_size 64k;
 92             #设定缓存文件夹大小,大于这个值,将从upstream服务器传
 93 
 94             fastcgi_connect_timeout 60s;
 95 
 96             fastcgi_send_timeout 60s;
 97 
 98             fastcgi_read_timeout 60s;
 99 
100             proxy_pass  http://tomcat;
101 
102             proxy_set_header Host $host;
103 
104             client_max_body_size 100m;    
105 
106             # WebScoket Support
107             proxy_http_version 1.1;
108             
109             proxy_set_header Upgrade $http_upgrade;
110             
111             proxy_set_header Connection "upgrade";
112             
113              } 
114      }  
115 
116  } 
117  
View Code

 可以添加一个nginx.bax快速操作nignx命令

@echo off
rem 提供Windows下nginx的启动,重启,关闭功能

echo ==================begin========================

cls
::ngxin 所在的盘符
set NGINX_PATH=%~d0

::nginx 所在目录
set NGINX_DIR=%cd% ginx-1.7.12
color 0a
TITLE Nginx 管理程序增强版

CLS

echo.
echo. ** Nginx 管理程序 ***
echo. *** create 2017-09-22 ***
echo.

:MENU

echo. ***** nginx 进程list ******
::tasklist|findstr /i "nginx.exe"
tasklist /fi "imagename eq nginx.exe"

echo.

if ERRORLEVEL 1 (
echo nginx.exe不存在
) else (
echo nginx.exe存在
)

echo.
::*************************************************************************************************************
echo.
echo. [1] 启动Nginx
echo. [2] 关闭Nginx
echo. [3] 重启Nginx
echo. [4] 刷新控制台
echo. [5] 重新加载Nginx配置文件
echo. [6] 检查测试nginx配置文件
echo. [7] 查看nginx version
echo. [0] 退 出
echo.

echo.请输入选择的序号:
set /p ID=
IF "%id%"=="1" GOTO start
IF "%id%"=="2" GOTO stop
IF "%id%"=="3" GOTO restart
IF "%id%"=="4" GOTO MENU
IF "%id%"=="5" GOTO reloadConf
IF "%id%"=="6" GOTO checkConf
IF "%id%"=="7" GOTO showVersion
IF "%id%"=="0" EXIT
PAUSE

::*************************************************************************************************************
::启动
:start
call :startNginx
GOTO MENU

::停止
:stop
call :shutdownNginx
GOTO MENU

::重启
:restart
call :shutdownNginx
call :startNginx
GOTO MENU

::检查测试配置文件
:checkConf
call :checkConfNginx
GOTO MENU

::重新加载Nginx配置文件
:reloadConf
call :checkConfNginx
call :reloadConfNginx
GOTO MENU

::显示nginx版本
:showVersion
call :showVersionNginx
GOTO MENU


::*************************************************************************************
::底层
::*************************************************************************************
:shutdownNginx
echo.
echo.关闭Nginx......
taskkill /F /IM nginx.exe > nul
echo.OK,关闭所有nginx 进程
goto :eof

:startNginx
echo.
echo.启动Nginx......
IF NOT EXIST "%NGINX_DIR%nginx.exe" (
echo "%NGINX_DIR%nginx.exe"不存在
goto :eof
)

%NGINX_PATH%
cd "%NGINX_DIR%"

IF EXIST "%NGINX_DIR%nginx.exe" (
echo "start '' nginx.exe"
start "" nginx.exe
)
echo.OK
goto :eof


:checkConfNginx
echo.
echo.检查测试 nginx 配置文件......
IF NOT EXIST "%NGINX_DIR%nginx.exe" (
echo "%NGINX_DIR%nginx.exe"不存在
goto :eof
)

%NGINX_PATH%
cd "%NGINX_DIR%"
nginx -t -c conf/nginx.conf

goto :eof

::重新加载 nginx 配置文件
:reloadConfNginx
echo.
echo.重新加载 nginx 配置文件......
IF NOT EXIST "%NGINX_DIR%nginx.exe" (
echo "%NGINX_DIR%nginx.exe"不存在
goto :eof
)

%NGINX_PATH%
cd "%NGINX_DIR%"
nginx -s reload

goto :eof

::显示nginx版本
:showVersionNginx
echo.
%NGINX_PATH%
cd "%NGINX_DIR%"
nginx -V
goto :eof

原文地址:https://www.cnblogs.com/songStar/p/11059670.html