前言:php
參考 http://www.javashuo.com/article/p-mdkyzppt-ba.htmlhtml
Nginx的應用場景
一、 http服務器。Nginx是一個http服務能夠獨立提供http服務。能夠作網頁靜態服務器。nginx
二、 虛擬主機。能夠實如今一臺服務器虛擬出多個網站。例如我的網站使用的虛擬主機。服務器
基於端口的,不一樣的端口
基於域名的,不一樣域名
三、 反向代理,負載均衡。當網站的訪問量達到必定程度後,單臺服務器不能知足用戶的請求時,須要用多臺服務器集羣可使用nginx作反向代理。而且多臺服務器能夠平均分擔負載,不會由於某臺服務器負載高宕機而某臺服務器閒置的狀況。session
一、到官網下載nginx安裝包。以下圖所示(建議安裝穩定版本):app
二、解壓安裝包,以下圖所示:負載均衡
三、開始安裝(建議用cmd命令執行安裝)tcp
1)定位到加壓文件根目錄:cd C:\nginx-1.14.0ide
2)安裝:C:\server\nginx-1.14.0>start nginx網站
四、其餘命令
中止: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 }