nginx 方向代理

#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,我们需要掌握一些基本的操作命令,比如:启动、停止Nginx服务,重新载入Nginx等,下面我就进行一些简单的介绍。
1、启动:
C:\server\nginx-1.0.2>start nginx或
C:\server\nginx-1.0.2>nginx.exe
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 方向代理的更多相关文章
- 微信小程序使用nginx方向代理实现内嵌非业务域名
通过上一篇文章简单介绍了一下微信小程序的新组件<web-view>,实现了在小程序中内嵌业务域名的功能.但是boss要的小程序中不仅想内嵌业务域名,还想要打开一些非业务域名(无法操作web ...
- nginx方向代理详解及配置
一代理服务器1.代理服务器,客户机在发送请求时,不会直接发送给目的主机,而是先发送代理服务器,代理服务器接受客户机请求之后,在向主机发出,并接受目的主机返回的数据,存放在代开服务器的硬盘中,在发送给客 ...
- nginx方向代理
nginx 的安装 # yum install nginx 新建配置文件 # vi /etc/nginx/conf.d/resume-xyz-8081.conf 配置 upstream resume ...
- nginx 方向代理 jenkins
环境 10.0.0.20 Nginx 10.0.0.21 jenkins 10.0.0.20 nginx 进入到nginx目录,去除无用字段输入到conf.d/jenkins.conf 文件中 [ro ...
- nginx高性能WEB服务器系列之七--nginx反向代理
nginx系列友情链接:nginx高性能WEB服务器系列之一简介及安装https://www.cnblogs.com/maxtgood/p/9597596.htmlnginx高性能WEB服务器系列之二 ...
- nginx 配置方向代理出错 The character [_] is never valid in a domain name
nginx 配置方向代理出错 The character [_] is never valid in a domain name 下面是配置信息: 原因是使用的tomcat为8及以上的版本时upstr ...
- Nginx 的方向代理及配置
最近有打算研读nginx源代码,看到网上介绍nginx可以作为一个反向代理服务器完成负载均衡.所以搜罗了一些关于反向代理服务器的内容,整理综合. 一 概述 反向代理(Reverse Proxy)方式 ...
- 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,放置 ...
- 最简单实现跨域的方法:用 Nginx 反向代理
本文作者: 伯乐在线 - 良少 .未经作者许可,禁止转载!欢迎加入伯乐在线 专栏作者. 什么是跨域 跨域,指的是浏览器不能执行其他网站的脚本.它是由浏览器的同源策略造成的,是浏览器对javascrip ...
随机推荐
- [转]ASP.NET Core Exception Filters and Resource Filters
本文转自:https://damienbod.com/2015/09/30/asp-net-5-exception-filters-and-resource-filters/ This article ...
- webpack+babel+react操作小结
最近学习了一下Webpack,个人感觉还是非常实用的,现在总结一下自己的学习笔记. 什么是 Webpack Webpack 是一个模块打包器.它将根据模块的依赖关系进行静态分析,然后将这些模块按照指定 ...
- vue——组件
一.组件概念 vue的核心基础就是组件的使用,玩好了组件才能将前面学的基础更好的运用起来.组件的使用更使我们的项目解耦合.更加符合vue的设计思想MVVM. // 定义一个名为 button-coun ...
- 五校联考模拟赛Day2T2矩阵(容斥原理)
题意 $n * m$的网格,对其进行黑白染色,问每一行每一列至少有一个黑格子的方案数. Sol 考场上只会$n^3$的dp,还和指数级枚举一个分qwq 设$f[i][j]$表示到了第$i$行,已经有$ ...
- CSS如何设置换行文字自动对齐
CSS如何设置换行文字自动对齐 如图所示: 代码实现如下: <ul class='warn-page-content'> <li> ...
- ARM-IoT
http://tech.hqew.com/fangan_723798 物联网就是一个物品互联网,这里的物品(物)内部有电子系统,具有感知和上报功能,支持远程控制,有时还能做出简单的决策.与物联网相关的 ...
- .NET开源工作流RoadFlow-表单设计-组织机构选择
组织机构选择即在表单中添加组织机构选择框. 选择范围: 1.发起者部门:只能在发起者同一个部门中选择. 2.处理者部门:只能在当前处理者同一个部门中选择. 3.自定义:自己指定一个选择范围. 选择类型 ...
- MVG配置
MVG的配置:(前提是一个表的字段包含多值字段,一般是1:M或M:M的关系) 想要在学生界面显示多个教师的名称. 1.首先在一个Project中,建两张表学生表和教师表T_Stu与T_Tea和一张中间 ...
- xshell里的一些配色方案
只需要把下面的代码复制到记事本中,保存为xcs文件格式,然后在xshell中导入选中就可以换配色方案了,可以自己修改下面的代码 [ubuntu]text(bold)=ffffffmagenta(bol ...
- day011-网络编程
1. 网络编程概述 1.1 网络编程三要素 地址.端口.协议 1.1.1 IP地址:网络中设备的唯一标识. IPV4格式:xxx.xxx.xxx.xxx由四段数字组成,每一段数字由八位二进制数字组成 ...