搜索
首页运维NginxWindows安装nginx1.10.1反向代理访问IIS网站的方法

首先去官网下载软件包,解压,路径最好不要有中文

nginx配置的路径问题

由于在windows下文件路径可以用”\”, 也可以用”\\”, 也可以用”/”作为路径做分隔符。但”\”最容易引发问题,所以要尽量避免使用。

不要添加path,否则会引发错误,config文件路径找不到

比如我解压在e盘

cmd命令定位到nginx.exe所在文件夹cd e:\worksoftware\nginx-1.10.1
然后执行,首先保证nginx.conf文件配置没问题

其实nginx最重要的和最主要的工作就是配置文件,其他没什么需要我们应用开发人员关注的,除非想修改底层源码.
nginx.conf配置如下:

#user nobody; 
worker_processes 1; 
#工作进程的个数,可以配置多个 
 
#全局错误日志及pid文件 
error_log /worksoftware/nginx-1.10.1/logs/error.log; 
#error_log logs/error.log notice; 
#error_log logs/error.log info; 
 
pid  /worksoftware/nginx-1.10.1/logs/nginx.pid; 
 
 
events { 
 worker_connections 1024; #单个进程最大连接数(最大连接数=连接数*进程数) 
} 
 
#设定http服务器,利用它的反向代理功能提供负载均衡支持 
http { 
 include  mime.types; #设定配置文件位置,这里的conf是指nginx.conf所在的目录,也可以用绝对路径指定其他地方的配置文件 
 default_type application/octet-stream; #默认类型-8进制文件流 
 
 #设定日志格式 
 #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 /worksoftware/nginx-1.10.1/logs/access.log main; 
 
 sendfile  on; #是否激活sendfile()函数,比默认模式更有效率 
 #tcp_nopush  on; #将http响应头压缩到一个包中发送,仅在sendfile开启时才能配合使用 
 
 #连接超时时间 
 #keepalive_timeout 0; 
 keepalive_timeout 65; 
 
 gzip on; #启用gzip压缩 
 
 #服务器的集群 
 #设定负载均衡的服务器列表 支持多组的负载均衡,可以配置多个upstream 来服务于不同的server. 
 #nginx 的 upstream 支持 几 种方式的分配 
 #1)、轮询(默认) 每个请求按时间顺序逐一分配到不同的后端服务器,如果后端服务器down掉,能自动剔除。 
 #2)、weight 指定轮询几率,weight和访问比率成正比,用于后端服务器性能不均的情况。 跟上面样,指定了权重。 
 #3)、ip_hash 每个请求按访问ip的hash结果分配,这样每个访客固定访问一个后端服务器,可以解决session的问题。 
 #4)、fair   
 #5)、url_hash #urlhash 
  
 #upstream imicrosoft.net 
 #{ 
  #服务器集群名字 
  #服务器配置 weight是权重的意思,权重越大,分配的概率越大。 
  #server 192.98.12.60:1985 weight=3 max_fails=2 fail_timeout=30s; 
  #server 192.98.12.42:8086 weight=3 max_fails=2 fail_timeout=30s; 
   
  #weigth参数表示权值,权值越高被分配到的几率越大 
  #1.down 表示单前的server暂时不参与负载 
  #2.weight 默认为1.weight越大,负载的权重就越大。  
  #3.backup: 其它所有的非backup机器down或者忙的时候,请求backup机器。所以这台机器压力会最轻。   
  #本例是指在同一台服务器,多台服务器改变ip即可  
 # server 127.0.0.1:8055 weight=4 down; 
 # server 127.0.0.1:8010 weight=5 backup; 
 #} 
  
  
 upstream localhost 
 {  
  server 127.0.0.1:9000 weight=3 max_fails=2 fail_timeout=200s; 
  server 127.0.0.1:8086 weight=5 max_fails=2 fail_timeout=200s; 
 } 
  
  
 #当前的nginx的配置,代理服务器的地址,即nginx安装的服务器地址、监听端口、默认地址, 
 #设定虚拟主机,默认为监听80端口 
 server 
 { 
  listen  9090; #侦听9090端口 
  #对于server_name,如果需要将多个域名的请求进行反向代理,可以配置多个server_name来满足要求 
  server_name localhost; #当前服务的域名 
   
  charset utf8; 
  #charset koi8-r; 
  
  #设定本虚拟主机的访问日志 
  #access_log logs/host.access.log main; 
 
   
  #如果访问 /images/*, /js/*, /css/* 资源,则直接取本地文件,不用转发。 
  #但如果文件较多效果不是太好。 
  #location ~ .*\.(jpg|jpeg|gif|css|png|ico|html)$ 
  #{ 
  # expires 30d; 
  # root /nginx-1.10.1;#root: 
  # break; 
  #} 
   
  #对 "/" 启用负载均衡 
  location / { 
    
   root html;  #默认主页目录在nginx安装目录的html子目录 
   
   index index.html index.htm index.aspx; #没有索引页时,罗列文件和子目录 
   #proxy_pass http://www.imicrosoft.net; #跟载均衡服务器的upstream对应     
   autoindex on; #没有索引页时,罗列文件和子目录 
   
   #保留用户真实信息 
   proxy_redirect off; #url不跳转 
   proxy_set_header host $host; 
   proxy_set_header x-real-ip $remote_addr; 
   proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for; 
   #缓冲区代理缓冲用户端请求的最大字节数,可以理解为先保存到本地再传给用户 
   # client_body_buffer_size 128k; 
   # #跟后端服务器连接超时时间 发起握手等候响应超时时间 
   # proxy_connect_timeout 12; 
   # #连接成功后 等待后端服务器响应时间 其实已进入后端的排队之中等候处理 
   # proxy_read_timeout 90; 
   # #代理请求缓存区 这个缓存区间会保存用户的头信息一共nginx进行规则处理 一般只要能保存下头信息即可 
   # proxy_send_timeout 90; 
   # #同上 告诉nginx保存单个用的几个buffer最大用多大空间 
   # proxy_buffer_size 4k; 
   # proxy_buffers 4 32k; 
   # #如果系统很忙的时候可以申请国内各大的proxy_buffers 官方推荐 *2 
   # proxy_busy_buffers_size 64k; 
   # #proxy 缓存临时文件的大小 
   proxy_temp_file_write_size 64k; 
   # proxy_next_upstream error timeout invalid_header http_500 http_503 http_404; 
   proxy_max_temp_file_size 128m; 
   #启动代理 
   proxy_pass http://localhost; 
   client_max_body_size 10m; #允许客户端请求的最大单个文件字节数 
  } 
 
   
   
  #示例一 
  #location / { 
  #  proxy_pass http://imicrosoft.net; 
  #  
  #  proxy_redirect default; 
  #   
  #  proxy_set_header host $host; 
  #  proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for; 
  #} 
   
  #示例二 
  #location /tileservice { 
  #  proxy_pass http://cluster/mongotileservice/tileservice; 
  #  proxy_set_header host $host; 
  #  proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for; 
  #} 
   
   
  #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 
  #对 "/xxxxx.php" 启用负载均衡 
  #location ~ \.php$ { 
  # proxy_pass http://127.0.0.1; 
  #} 
   
  #location /baidu 
  #{ 
  #proxy_pass http://www.google.com; 
  #proxy_set_header host $host; 
  #proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for; 
  #} 
   
  # 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; 
 # } 
 #} 
 
}

结果如图:

Windows安装nginx1.10.1反向代理访问IIS网站的方法

Windows安装nginx1.10.1反向代理访问IIS网站的方法

Windows安装nginx1.10.1反向代理访问IIS网站的方法

iis站点

Windows安装nginx1.10.1反向代理访问IIS网站的方法

以上是Windows安装nginx1.10.1反向代理访问IIS网站的方法的详细内容。更多信息请关注PHP中文网其他相关文章!

声明
本文转载于:亿速云。如有侵权,请联系admin@php.cn删除
nginx怎么启动php服务器nginx怎么启动php服务器Apr 14, 2025 am 11:51 AM

Nginx 通过 FastCGI 或 PHP-FPM 启动 PHP 服务器,具体步骤包括:安装 FastCGI 模块并配置 Nginx 配置文件,指定 PHP-FPM 套接字文件的位置。安装并配置 PHP-FPM,设置监听套接字文件和启动 PHP-FPM。在 Nginx 配置文件中添加代理 pass 配置,将 PHP 请求转发给 PHP-FPM 服务器(通常是 127.0.0.1:9000)。启动 Nginx,测试访问 PHP 文件以验证 PHP 服务器是否已启动。

nginx怎么查看运行状态nginx怎么查看运行状态Apr 14, 2025 am 11:48 AM

查看 Nginx 运行状态的方法有:使用 ps 命令查看进程状态;查看 Nginx 配置文件 /etc/nginx/nginx.conf;使用 Nginx 状态模块启用状态端点;使用 Prometheus、Zabbix 或 Nagios 等监控工具。

nginx变量怎么用nginx变量怎么用Apr 14, 2025 am 11:45 AM

Nginx 变量是用来存储信息的占位符,可通过 $variable_name 使用。常用变量包括 $arg_variable_name(URL 参数)、$host(主机名)、$http_host(HTTP 主机头)、$method(请求方法)、$remote_addr(客户端 IP)、$request_uri(URI)、$server_name(服务器名称)和 $time_local(服务器时间)。这些变量可以用于记录访问日志、重定向请求和定制响应。

nginx服务器挂了怎么办nginx服务器挂了怎么办Apr 14, 2025 am 11:42 AM

当 Nginx 服务器宕机时,可执行以下故障排除步骤:检查 nginx 进程是否正在运行。查看错误日志以获取错误消息。检查 nginx 配置语法正确性。确保 nginx 具有访问文件所需的权限。检查文件描述符打开限制。确认 nginx 正在侦听正确的端口。添加防火墙规则以允许nginx流量。检查反向代理设置,包括后端服务器可用性。如需进一步帮助,请联系技术支持。

nginx服务怎么停止nginx服务怎么停止Apr 14, 2025 am 11:39 AM

停止 Nginx 服务可通过以下步骤完成:确认 Nginx 正在运行;使用 systemd:sudo systemctl stop nginx;对于较旧系统,使用 init.d:sudo service nginx stop;使用命令行:sudo /etc/init.d/nginx stop;验证停止:检查输出显示 "inactive (dead)" 或 "stopped"。

怎么把nginx访问地址设置成服务器ip怎么把nginx访问地址设置成服务器ipApr 14, 2025 am 11:36 AM

要在 Nginx 中将访问地址设置为服务器 IP,请:配置服务器块,设置监听地址(如:listen 192.168.1.10:80)设置服务器名称(如:server_name example.com www.example.com),或将其留空以访问服务器 IP保存并重新加载 Nginx 以应用更改

nginx命令怎么关闭nginx命令怎么关闭Apr 14, 2025 am 11:33 AM

关闭 nginx 的命令是 nginx -s quit。该命令向 nginx 进程发送 QUIT 信号,导致 nginx 正常关闭。其他选项包括:1. -s stop:强制立即关闭 nginx。2. -s reopen:导致 nginx 重新打开日志文件。

nginx怎么配置域名nginx怎么配置域名Apr 14, 2025 am 11:30 AM

要在 Nginx 中配置域名,遵循以下步骤:添加 Server 块,指定域名。设置网站文件的根目录。设置根目录下的索引文件。设置错误代码的处理方式。配置服务器访问和错误日志。重新加载或重启 Nginx 服务。

See all articles

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

AI Hentai Generator

AI Hentai Generator

免费生成ai无尽的。

热门文章

R.E.P.O.能量晶体解释及其做什么(黄色晶体)
3 周前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳图形设置
3 周前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您听不到任何人,如何修复音频
3 周前By尊渡假赌尊渡假赌尊渡假赌
WWE 2K25:如何解锁Myrise中的所有内容
4 周前By尊渡假赌尊渡假赌尊渡假赌

热工具

VSCode Windows 64位 下载

VSCode Windows 64位 下载

微软推出的免费、功能强大的一款IDE编辑器

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

WebStorm Mac版

WebStorm Mac版

好用的JavaScript开发工具

安全考试浏览器

安全考试浏览器

Safe Exam Browser是一个安全的浏览器环境,用于安全地进行在线考试。该软件将任何计算机变成一个安全的工作站。它控制对任何实用工具的访问,并防止学生使用未经授权的资源。

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境