1.进入Nginx官网下载
2.选怎一个稳定版本,下载
3.解压D:\nginx-1.10.3
点击nginx.exe Nginx就行运行了。
查看进程的命令:
tasklist /fi "imagename eq nginx.exe"
停止Nginx
nginx -s stop强制关闭 taskkill /F /IM nginx.exe > nul
nginx -s quit 安全关闭
nginx -s reload 改变配置文件的时候,重启nginx工作进程,来时配置文件生效
nginx -s reopen 打开日志文件
4.常用的配置
D:\nginx-1.10.3\conf\nginx.conf
#user root;
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 myproject {
#ip_hash;
#weigth参数表示权值,权值越高被分配到的几率越大。
#weight 是权重,数字越大,优先级越高!max_fails 为最大失效次数!fail_timeout 为超时时间!
server xxxxxx:8099 weight=10;
}
server {
listen 8141;
server_name localhost 136.64.68.42 qc.tj.189.cn;
client_max_body_size 10m;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root /home/chnweb/eshop/application/bjteleApp;
index login/login.html;
#index partner/index.html;
rewrite "^[/]?$" "/index.html" last;
proxy_set_header Host $host;
proxy_set_header X-Forwarxded-For $remote_addr;
proxy_pass http://myproject;
}
location ~ .*\.(html|css|js|gif|jpg|jpeg|png|json|ico|tff)$ {
root /home/chnweb/eshop/application/bjteleApp;
index login/login.html;
expires 2h;
#index partner/index.html;
}
location ^~ /tmp/ { #b.配置本地图片路径(图片存在d盘:portal/file文件夹下,注意前后的“/”不可省略),完整访问地址为第http://localhost/portal/file/xxxxx.jpg
root /home/chnweb/eshop/qrcodePicture/; #a.设置nginx根目录为d盘。
}
location ^~ /upload/image/ { #b.配置本地图片路径(图片存在d盘:portal/file文件夹下,注意前后的“/”不可省略),完整访问地址为第http://localhost/portal/file/xxxxx.jpg
root /home/chnweb/eshop/apache-tomcat-7.0.82/webapps/ROOT/; #a.设置nginx根目录为d盘。
}
location /index/{
root /home/chnweb/eshop/application/bjteleApp/login;
index login.html;
}
location /favicon.ico {
log_not_found off;
access_log off;
}
#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;
# }
#}
}