前言:
参考 https://blog.csdn.net/kisscatforever/article/details/73129270
Nginx的应用场景
1、 http服务器。Nginx是一个http服务可以独立提供http服务。可以做网页静态服务器。
2、 虚拟主机。可以实现在一台服务器虚拟出多个网站。例如个人网站使用的虚拟主机。
基于端口的,不同的端口
基于域名的,不同域名
3、 反向代理,负载均衡。当网站的访问量达到一定程度后,单台服务器不能满足用户的请求时,需要用多台服务器集群可以使用nginx做反向代理。并且多台服务器可以平均分担负载,不会因为某台服务器负载高宕机而某台服务器闲置的情况。
1、到官网下载nginx安装包。如下图所示(建议安装稳定版本):
2、解压安装包,如下图所示:
3、开始安装(建议用cmd命令执行安装)
1)定位到加压文件根目录:cd C:\nginx-1.14.0
2)安装:C:\server\nginx-1.14.0>start nginx
4、其他命令
停止:C:\server\nginx-1.14.0>nginx.exe -s stop
重新载入Nginx:C:\server\nginx-1.14.0>nginx.exe -s reload
查看Nginx版本:C:\server\nginx-1.14.0>nginx -v
========================配置nginx文件(以下为本地案例)===========================

1 #user nobody; 2 worker_processes 1; 3 4 #error_log logs/error.log; 5 #error_log logs/error.log notice; 6 #error_log logs/error.log info; 7 8 #pid logs/nginx.pid; 9 10 11 events { 12 worker_connections 1024; 13 } 14 15 16 http { 17 include mime.types; 18 default_type application/octet-stream; 19 20 #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' 21 # '$status $body_bytes_sent "$http_referer" ' 22 # '"$http_user_agent" "$http_x_forwarded_for"'; 23 24 #access_log logs/access.log main; 25 26 sendfile on; 27 #tcp_nopush on; 28 29 #keepalive_timeout 0; 30 keepalive_timeout 65; 31 32 #gzip on; 33 34 server { 35 listen 88; 36 server_name 127.0.0.1; 37 38 39 #charset koi8-r; 40 proxy_set_header Host 127.0.0.1:88; 41 proxy_set_header X-Real-IP $remote_addr; 42 proxy_set_header REMOTE-HOST $remote_addr; 43 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 44 #access_log logs/host.access.log main; 45 46 location ^~ /ProxyService/ { proxy_set_header Host $host; proxy_pass http://127.0.0.1:8067/; } 47 location ^~ /ph/ { proxy_set_header Host $host; proxy_pass http://127.0.0.1:8091/; } 48 location ^~ /report/ { proxy_set_header Host $host; proxy_pass http://127.0.0.1:90/; } 49 50 51 location ^~ /admin/ { proxy_pass http://127.0.0.1:88/; } 52 53 #其他路径默认访问前台网站 54 location / { 55 proxy_redirect off; 56 proxy_pass http://WeixinRespon; 57 proxy_set_header HOST $host; 58 proxy_set_header X-Real-IP $remote_addr; 59 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 60 } 61 62 63 64 #error_page 404 /404.html; 65 66 # redirect server error pages to the static page /50x.html 67 # 68 error_page 500 502 503 504 /50x.html; 69 location = /50x.html { 70 root html; 71 } 72 73 # proxy the PHP scripts to Apache listening on 127.0.0.1:80 74 # 75 #location ~ \.php$ { 76 # proxy_pass http://127.0.0.1; 77 #} 78 79 # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 80 # 81 #location ~ \.php$ { 82 # root html; 83 # fastcgi_pass 127.0.0.1:9000; 84 # fastcgi_index index.php; 85 # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; 86 # include fastcgi_params; 87 #} 88 89 # deny access to .htaccess files, if Apache's document root 90 # concurs with nginx's one 91 # 92 #location ~ /\.ht { 93 # deny all; 94 #} 95 } 96 97 upstream WeixinRespon { 98 server 127.0.0.1:8080; 99 } 100 101 # HTTPS server 102 # 103 #server { 104 # listen 443 ssl; 105 # server_name localhost; 106 107 # ssl_certificate cert.pem; 108 # ssl_certificate_key cert.key; 109 110 # ssl_session_cache shared:SSL:1m; 111 # ssl_session_timeout 5m; 112 113 # ssl_ciphers HIGH:!aNULL:!MD5; 114 # ssl_prefer_server_ciphers on; 115 116 # location / { 117 # root html; 118 # index index.html index.htm; 119 # } 120 #} 121 122 }