之前用.net做的网站,都是用iis ,现在应为一些需求 需要使用到nginx 配合使用,不多说,来实在的!
一、nginx 相关配置 自行百度吧 网上很多 。
demo:

1 upstream web_www{
2 server 127.0.0.1:5006;
3 server 192.168.1.1:5006;# 可以配置权重 访问方式
4 #可以更多个
5 }
6 server {
7 listen 80;
8 server_name xxx.domain.com;#域名
9
10 #如果是防止爬虫抓取的使用
11 if ($http_user_agent ~* "qihoobot|Baiduspider|Googlebot|Googlebot-Mobile|Googlebot-Image|Mediapartners-Google|Adsbot-Google|Feedfetcher-Google|Yahoo! Slurp|Yahoo! Slurp China|YoudaoBot|Sosospider|Sogou spider|Sogou web spider|MSNBot|ia_archiver|Tomato Bot")
12 {
13 return 403;
14 }
15
16 location / {
17 proxy_set_header X-Real-IP $remote_addr;
18 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
19 proxy_set_header Host $http_host;
20 proxy_set_header X-NginX-Proxy true;
21 proxy_pass http://web_www;
22
23 proxy_redirect off;
24 client_max_body_size 20m;
25 }
26 root html;
27 index index.aspx;
28
29
30 error_page 500 502 503 504 /50x.html;
31 location = /50x.html {
32 root html;
33 }
34
35 }
View Code
二、nginx 启动不成功:
如果服务器已经安装了iis ,想使用nginx 可能遇到各种坑,各种80占用 nginx启动不成功, 注意查看nginx的logs下的错误信息
可能是配置错误导致启动不成功,
例如:如果是第一行错误,一般第一行是注释掉的不会出问题,那么应该是包含bom格式的编码
如果出现 bind() to 0.0.0.0:80 failed (10013: An attempt was made to access a socket in a way forbidden by its access permissions) 那基本上就妥妥的是80端口占用了
解决方法是a. telnet 127.0.0.1 80 然后回车 应该有提示
1 如果是iis占用会有 这样样 HTTP/1.1 400 Bad Request Content-Type: text/html; charset=us-ascii Server: Microsoft-HTTPAPI/2.0 之类的 停用iiis 试试
2 如果依然不行 停止 服务 iis admin 试试
b. netstat -aon | findstr "80" 在 tasklist 发现是 有个id 是4的 那就是 system这个进程了 解决方法是 :
1 如果有安装sql数据库 停用报表服务 ,
2 如果依然不行 打开注册表 运行 输入regedit 找到HKEY_LOCAL_MACHINESYSTEMCurrentControlSetservicesHTTP 修改项start 将3改为0
至此 基本上可以解决 ,解决方法顺序根据情况来
转载于:https://www.cnblogs.com/WindWall/p/8064743.html
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!