Nginx的使用

1,修改nginx.conf
#user  nobody;
worker_processes  4;

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

pid        logs/nginx.pid;

worker_rlimit_nofile 65535;

events {
    worker_connections  65535;
    multi_accept on;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] $host "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    server_tokens   off;
    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;
    
    upstream count_boss {
      server 192.168.8.236:3480;
    }

    server {
        listen       9191;
        server_name  192.168.8.47;

        #charset koi8-r;

        access_log logs/host.access.log;

        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;
        }
        
        # count_boss
        location /boss/ {
            proxy_redirect off;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Scheme $scheme;
            proxy_set_header Cookie $http_cookie;
            client_max_body_size 50m;
            client_body_buffer_size 256k;
            proxy_connect_timeout 75;
            proxy_send_timeout 120;
            proxy_read_timeout 300;
            proxy_buffer_size 256k;
            proxy_buffers 4 256k;
            proxy_busy_buffers_size 256k;
            proxy_temp_file_write_size 256k;
            # proxy_next_upstream error timeout invalid_header http_500 http_503 http_404;
            proxy_max_temp_file_size 128m;
            proxy_pass  http://count_boss/boss/;    #请求转向定义的服务器列表
        }
        

        # 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,nginx命令
## 关闭nginx
nginx -s stop


## 关闭nginx
taskkill /F /IM nginx.exe > null 


## 查看nginx
tasklist /fi "imagename eq nginx.exe"

## 测试nginx.conf正确性
nginx.exe –t


## start.bat
C:
cd C:\Users\lixj\Desktop\nginx-1.12.0
start nginx 


## stop.bat
C:
cd C:\Users\lixj\Desktop\nginx-1.12.0
taskkill /F /IM nginx.exe>nul


## reload.bat
C:
cd C:\Users\lixj\Desktop\nginx-1.12.0
nginx -s reload




## 分享下bat文件

====================================================
@echo off
rem 当前bat的作用

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

cls 
SET NGINX_PATH=C:
SET NGINX_DIR=C:\Users\lixj\Desktop\nginx-1.12.0\
color 0a 
TITLE Nginx 管理程序控制面板

CLS 

ECHO. 
ECHO. * Nginx Manage System *
ECHO. * Author lixj * 
ECHO. * Date 2017-05-19 * 
ECHO. 

:MENU 

ECHO. * nginx process list * 
tasklist|findstr /i "nginx.exe"

ECHO. 
ECHO. [1] 启动Nginx 
ECHO. [2] 关闭Nginx 
ECHO. [3] 重启Nginx 
ECHO. [4] 退 出 
ECHO. 

ECHO.请输入选择项目的序号:
set /p ID=
IF "%id%"=="1" GOTO start 
IF "%id%"=="2" GOTO stop 
IF "%id%"=="3" GOTO restart 
IF "%id%"=="4" EXIT
PAUSE 

:start 
call :startNginx
GOTO MENU

:stop 
call :shutdownNginx
GOTO MENU

:restart 
call :shutdownNginx
call :startNginx
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"不存在 

%NGINX_PATH% 

cd "%NGINX_DIR%" 

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

你可能感兴趣的:(Nginx的使用)