Nginx 反向代理配置
什么是nginx
- Nginx是一款轻量级Web服务器,也是一款反向代理服务器
- 官网:http://nginx.org/
- 中文文档: http://www.nginx.cn/doc/
nginx可以提供的服务有:
**1. web 服务
- 负载均衡 (反向代理)
- web cache(web 缓存**)
nginx常用命令
- 测试配置文件:${Nginx}/sbin/nginx -t
- 启动命令:${Nginx}/sbin/nginx
- 停止命令:${Nginx}/sbin/nginx -s stop/quit
- 重启命令:${Nginx}/sbin/nginx -s reload
- 查看进程命令:ps -ef | grep nginx
- 平滑重启:kill -HUP [Nginx主进程号(即ps命令查到的PID)]
nginx实现反向代理配置
1.打开 ${Nginx}/conf/nginx.conf 文件
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
# 这个server配置表示访问localhost:8081地址 将请求转发到这个server下定义的location位置上
server {
listen 8081;
server_name localhost;
# 这个location表示将localhost:8081地址转发到html文件夹下的index2.html首页上
location / {
root html;
index index2.html index.htm;
}
}
# 这个server表示访问localhost:80地址 将请求转发到这个server下定义的location位置上
server {
listen 80;
server_name localhost;
# 这个location表示将localhost:80请求 转发到index.html文件上
location / {
root html;
index index.html index.htm;
}
#location / {
#proxy_pass http://www.zzdy.wang:18537/;
# }
#这个location表示将localhost:80/demo/开头的请求 转发到http://localhost:8080/服务上
location /demo {
proxy_pass http://localhost:8080/;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
# nginx:http转发到https
HTTPS server
server {
listen 8069;
server_name www.zzdy**.cn;
rewrite ^(.*)$ https://$host$1 permanent;
}
}
# 在做请求转发时,一定要注意proxy_pass后/符号的添加,不加/表示访问 http://localhost:8080/demo+ 加/表示访问http://localhost:8080/+
还没有评论,来说两句吧...