使用nginx最初的目的是为了解决iis7下无法配置多个443端口的问题,iis7下不同的域名无法同时绑定443端口,据说iis8是可以的,但是iis8的话需要安装windows server2012,成本太高,不考虑。
Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,并在一个BSD-like 协议下发行。其特点是占有内存少,并发能力强。下载地址:http://nginx.org/en/download.html
nginx常用命令:
start nginx
nginx -s quit
nginx -s reload
找到nginx配置文件(nginx-1.12.2\conf\nginx.conf),修改如下(没有说明的配置项可以自己查阅官方文档):
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
client_header_timeout 15;
client_body_timeout 15;
send_timeout 25;
client_max_body_size 1024m;
server_names_hash_bucket_size 512;
#gzip on;
server {
listen 443 ssl;
server_name domain.com;
gzip on;
gzip_min_length 1k;
gzip_comp_level 9;
gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
gzip_vary on;
gzip_disable "MSIE [1-6]\.";
#ssl on;
ssl_certificate D:/nginx/cert/domain.com.pem;
ssl_certificate_key D:/nginx/cert/domain.com.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
error_page 500 502 503 504 /50x.html;
error_log logs/error.log error;
location / {
index index.html index.htm;
proxy_redirect off;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://localhost:8098/;
}
location /qrcode.jpg {
alias /home/qrcode.jpg;
break;
}
location /guzbBkK23R.txt {
alias /home/guzbBkK23R.txt;
break;
}
location /soft {
alias /home/upfile/soft/;
}
location /web {
alias /home/web/dist/;
index index.html index.htm;
}
location /market/ {
proxy_read_timeout 1800;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:8099/;
}
}
server {
listen 80;
server_name www.domain.com domain.com;
return 308 https://$server_name$request_uri; //不使用301转发,301对POST PUT DELETE操作等转发会自动换成GET操作
}
}
如果希望用户通过http访问时自动跳转到https,可以增加以下配置:
server {
listen 80;
server_name www.domain.com domain.com;
return 308 https://www.bdomain.net$request_uri; //不使用301转发,301对POST PUT DELETE操作等转发会自动换成GET操作
}
不跳转到https,但是接管80端口的配置:
server {
listen 80;
server_name www.domain.com domain.com;
location / {
proxy_pass http://www.domain.com:8088;
index Home/Index;
}
}