#nginx 监听原理 先监听端口 --> 再配置域名 -->匹配到就访问local 否则 没有匹配到域名就默认访问第一个监听端口的local地址

# vi nginx.conf
user nobody nobody; # 运 nginx的所属组和所有者
worker_processes 2; # 开启两个 nginx工作进程,一般几个 CPU核心就写几
error_log logs/error.log notice; # 错误日志路径
pid logs/nginx.pid; # pid 路径
events {
worker_connections 1024; # 一个进程能同时处理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;
  keepalive_timeout 65; # keepalive超市时间
  # 开始配置一个域名,一个server配置段一般对应一个域名
  server {
    listen 80; # 监听端口()
    # 在本机所有ip上监听80,也可以写为192.168.1.202:80,这样的话,就只监听192.168.1.202 上的80口
    server_name www.heytool.com; # 域名
    root /www/html/www.heytool.com; # 站点根目录(程序目录)
    index index.html index.htm; # 索引文件

    # 可以有多个 location
    location / {
      #proxy_pass www.baidu.com # 跳到 百度页面 (网址)
      root /www/html/www.heytool.com; # 站点根目录(程序目录) (本地的路径)
    }

    error_page 500 502 503 504 /50x.html;
    # 定义错误页面,如果是500错误,则把站点根目录下的50x.html返回给用户
    location = /50x.html {
    root /www/html/www.heytool.com;
  }
}

nginx 服务器重启命令,关闭

 Windows下Nginx的启动、停止等命令
在Windows下使用Nginx,我们需要掌握一些基本的操作命令,比如:启动、停止Nginx服务,重新载入Nginx等,下面我就进行一些简单的介绍。
1、启动:
C:\server\nginx-1.0.2>start nginx或
C:\server\nginx-1.0.2>nginx.exe
nginx -s reload  :修改配置后重新加载生效
nginx -s reopen  :重新打开日志文件
nginx -t -c /path/to/nginx.conf 测试nginx配置文件是否正确

关闭nginx:
nginx -s stop  :快速停止nginx
         quit  :完整有序的停止nginx

其他的停止nginx 方式:

--   定义 zyh.conf

upstream ioob.com {
server localhost:8888;
}
upstream tomcatserver2 {
server 192.168.72.49:8082;
}
server {
listen 8089;
server_name 8081.max.com;

#charset koi8-r;

#access_log logs/host.access.log main;

location / {
proxy_pass http://ioob.com;
index index.html index.htm;
}
}

--  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;
include zyhconfig/*.conf;
#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;

server {
listen 80;
server_name localhost;

#charset koi8-r;

#access_log logs/host.access.log main;

location / {
root html;
index index.html index.htm;
}

#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;
# }
#}

}

nginx 方向代理的更多相关文章

  1. 微信小程序使用nginx方向代理实现内嵌非业务域名

    通过上一篇文章简单介绍了一下微信小程序的新组件<web-view>,实现了在小程序中内嵌业务域名的功能.但是boss要的小程序中不仅想内嵌业务域名,还想要打开一些非业务域名(无法操作web ...

  2. nginx方向代理详解及配置

    一代理服务器1.代理服务器,客户机在发送请求时,不会直接发送给目的主机,而是先发送代理服务器,代理服务器接受客户机请求之后,在向主机发出,并接受目的主机返回的数据,存放在代开服务器的硬盘中,在发送给客 ...

  3. nginx方向代理

    nginx 的安装 # yum install nginx 新建配置文件 # vi /etc/nginx/conf.d/resume-xyz-8081.conf 配置 upstream resume ...

  4. nginx 方向代理 jenkins

    环境 10.0.0.20 Nginx 10.0.0.21 jenkins 10.0.0.20 nginx 进入到nginx目录,去除无用字段输入到conf.d/jenkins.conf 文件中 [ro ...

  5. nginx高性能WEB服务器系列之七--nginx反向代理

    nginx系列友情链接:nginx高性能WEB服务器系列之一简介及安装https://www.cnblogs.com/maxtgood/p/9597596.htmlnginx高性能WEB服务器系列之二 ...

  6. nginx 配置方向代理出错 The character [_] is never valid in a domain name

    nginx 配置方向代理出错 The character [_] is never valid in a domain name 下面是配置信息: 原因是使用的tomcat为8及以上的版本时upstr ...

  7. Nginx 的方向代理及配置

    最近有打算研读nginx源代码,看到网上介绍nginx可以作为一个反向代理服务器完成负载均衡.所以搜罗了一些关于反向代理服务器的内容,整理综合. 一  概述 反向代理(Reverse Proxy)方式 ...

  8. Nginx 反向代理、负载均衡、页面缓存、URL重写以及读写分离

    1.环境准备 前端Nginx:10.160.65.44 后端WEB服务器两台:10.160.65.49/10.160.65.50 2.安装Nginx: 下载nginx-1.9.15.tar.gz,放置 ...

  9. 最简单实现跨域的方法:用 Nginx 反向代理

    本文作者: 伯乐在线 - 良少 .未经作者许可,禁止转载!欢迎加入伯乐在线 专栏作者. 什么是跨域 跨域,指的是浏览器不能执行其他网站的脚本.它是由浏览器的同源策略造成的,是浏览器对javascrip ...

随机推荐

  1. javascript小数相减出现一长串的小数位数

    我们要修改网页某个数据的显示格式,需要两步操作: 1.在JS中通过$('.class1 .class2 li:eq(2) span.value').text().trim();类似的语句获取到数据内容 ...

  2. js之正则表达式基础

    字符串是编程时涉及到的最多的一种数据结构,对字符串进行操作的需求几乎无处不在.比如判断一个字符串是否是合法的Email地址,虽然可以编程提取@前后的子串,再分别判断是否是单词和域名,但这样做不但麻烦, ...

  3. 【数据库】3.0 MySQL入门学习(三)——Windows系统环境下MySQL安装

    1.0 我的操作系统是window10 专业版 64位.,不过至少windows7以上系统都是一样的. 关于MySQL如何下载,请参考博文: [数据库]2.0 如何获得MySQL以及MySQL安装 h ...

  4. Java 重写hashCode() 时为什么要用 31 来计算

    在OSChina 中看到了一篇文章<Java 中正确使用 hashCode 和 equals 方法>,看到 hashCode 的方法体内的31比较有意思. 在Stackoverflow上找 ...

  5. 缩短移动开发周期的ApiCloud

    ApiCloud百度百科介绍: ApiCloud 官网 官方论坛 APICloud经典O2O案例APP视频教程

  6. idea 新建文件夹目录问题解决

    选中工程,设置,去掉选项“Compact Empty Middle Packages” .

  7. Hadoop ->> 关于数据分割(Data Split)的思考

    今天开始学习Hadoop这门热门的数据库技术.直接从被奉为Hadoop圣经的<Hadoop The Definitive Guide 4th Edition>入手.第一章作者写到一个关于分 ...

  8. Kubernetes stateful set讲解以及一个基于postgreSQL的具体例子

    Stateful Set是Kubernetes 1.9版本新引入的一个概念,用于管理有状态的应用. Kubernetes官方文档: https://kubernetes.io/docs/concept ...

  9. Visual Stuio 2010 常用快捷及操作

    1.如果你想复制一行代码(超级长,鼠标拖老久的),只需要在这行的空白处 CTRL+C 同理,剪贴一行 CTRL+X 删除一行 CTRL+L 2.显示方法里的参数,以前每次都是手动删括号. CTRL+S ...

  10. wireshark抓取本地回环数据包

      linux环境下,用tcpdump,可以用-i lo参数抓取环回接口的包.如果服务端和客户端安装在同一台机器上,调试时是很方便的.linux版的wireshark,选取网卡的菜单里也有lo选项,也 ...