下載地址:
http://nginx.org/en/download.html
下載完成後解壓
直接cmd到本路徑下
然後用命令啓動(也可以直接點擊Nginx直接啓動)
啓動
直接點擊Nginx目錄下的nginx.exe 或者 cmd運行start nginx
關閉
nginx -s stop 或者 nginx -s quit
stop表示立即停止nginx,不保存相關信息
quit表示正常退出nginx,並保存相關信息
重啓(因爲改變了配置,需要重啓)
nginx -s reload
啓動完成後可以先試試輸入localhost訪問,如果出現nginx啓動界面說明啓動正常
接下來修改配置:
#user nobody;
worker_processes 1;#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;#keepalive_timeout 0;
keepalive_timeout 65;gzip on;
upstream localtomcat { #服務器集羣名字,這裏我用本地模擬
# least_conn;//負載策略
server 192.168.50.111:8080 fail_timeout=30s; #localhost時會自動切換,ip時不自動
server 192.168.50.111:8081 fail_timeout=30s;
server 192.168.50.111:8082 fail_timeout=30s;
}
server {
listen 80;
server_name localhost;#charset koi8-r;
#access_log logs/host.access.log main;
# location / {
# root html;
# index index.html index.htm;
# proxy_pass http://localtomcat;
#}
# 所有動態請求都轉發給tomcat處理
location /so/{ #此處配置rest接口代理
proxy_next_upstream http_502 http_504 error timeout invalid_header;
proxy_pass http://localtomcat; #這裏與上面配置的upstream 名字要相同
}
#靜態文件交給nginx處理
location ~ .*\.(htm|html|gif|jpg|jpeg|png|bmp|swf|ioc|rar|zip|txt|flv|mid|doc|ppt|pdf|xls|mp3|wma)$
{
root E:\2; #靜態資源路徑
}
#靜態文件交給nginx處理
location ~ .*\.(js|css)?$
{
root E:\2;
}
#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;
}# 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;
# }
#}}