首页 > 系统相关 >nginx使用

nginx使用

时间:2022-11-17 16:34:29浏览次数:36  
标签:set http header pass nginx proxy 使用 location

nginx 目录

如图:
图片

  1. logs 可以记录 nginx 中的报错信息。
  2. html 存放打包好的项目资源。
  3. conf 中的 nginx.config 可以设置访问端口号和代理地址。

nginx 使用

  1. 下载 nginx
  2. 把打包好的项目目录放在 html 文件夹中
  3. 根据 nginx.config 中的端口号,打开浏览器用 http://localhost:端口号/#/index 访问

nginx.config 配置详解

nginx 配置样例

例如页面请求地址为http://www.sayhi.com/products/pageManage,则在nginx.conf中配置server如下:

server {
       listen 80;  #监听80的服务端口
       server_name www.sayhi.com;  #监听的域名
        location /{
                root emstatic;
                index index.html;

        location /products {
                proxy_pass http://127.0.0.1:8103/zuul-product/product/manage;
                add_header 'Access-Control-Allow-Credentials' 'true';
                add_header 'Access-Control-Allow-Origin' '*';
        }
}

根据域名www.sayhi.com和后缀/products匹配到server中的server_name和location后,将剩余url后缀/pageManage拼接到location中的配置项proxy_pass的url后通过网关访问服务器资源。
所以访问http://www.sayhi.com/products/pageManage时经过nginx配置后实际访问的地址为http://127.0.0.1:8103/zuul-product/product/manage/pageManage。

nginx.config文件


#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;
	
	client_max_body_size 10m;
	
    sendfile        on;
    keepalive_timeout  65;
	
	 root html;
	 index index.html index.hml;
	
    # websocket配置所需
    map $http_upgrade $connection_upgrade {
        default upgrade;
        ''      close;
    }

    server {
		listen       9111 ssl;
        server_name  localhost;
        # server_name   10.8.3.225;
        # server_name   sso3.towatt.cn;
		
		ssl on;
		ssl_certificate      towatt.cn.crt;
        ssl_certificate_key  towatt.cn.key;
        
        # websocket配置所需
        location /ws {
            proxy_pass http://192.168.30.137:20501/backlog/data;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection $connection_upgrade;
        }

        location / {
            root   html;
            index  index.html index.htm;
        }
		location /index/ {
            proxy_pass http://127.0.0.1:8080/;
			proxy_set_header Host  $host;
           proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
           proxy_set_header X-Real-IP  $remote_addr;
        }
		
		location /auth/ {
            proxy_pass http://127.0.0.1:8081/;
			proxy_set_header Host  $host;
           proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
           proxy_set_header X-Real-IP  $remote_addr;
        }
		
		location /activity/ {
            proxy_pass http://127.0.0.1:8082/;
			proxy_set_header Host  $host;
           proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
           proxy_set_header X-Real-IP  $remote_addr;
        }
		
		
		location /system/ {
            proxy_pass http://127.0.0.1:8083/;
			proxy_set_header Host  $host;
           proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
           proxy_set_header X-Real-IP  $remote_addr;
        }
		
		location /finance/ {
            proxy_pass http://127.0.0.1:8084/;
			proxy_set_header Host  $host;
           proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
           proxy_set_header X-Real-IP  $remote_addr;
        }
		
		location /manage/ {
            proxy_pass http://127.0.0.1:8085/;
			proxy_set_header Host  $host;
           proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
           proxy_set_header X-Real-IP  $remote_addr;
        }
		
		location /operation/ {
            proxy_pass http://127.0.0.1:8086/;
			proxy_set_header Host  $host;
           proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
           proxy_set_header X-Real-IP  $remote_addr;
        }
		
		location /trace/ {
            proxy_pass http://127.0.0.1:8087/;
			proxy_set_header Host  $host;
           proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
           proxy_set_header X-Real-IP  $remote_addr;
        }
		
		location /government/ {
            proxy_pass http://127.0.0.1:8088/;
			proxy_set_header Host  $host;
           proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
           proxy_set_header X-Real-IP  $remote_addr;
        }
		
		location /vip/ {
            proxy_pass http://127.0.0.1:8089/;
			proxy_set_header Host  $host;
           proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
           proxy_set_header X-Real-IP  $remote_addr;
        }
		
		location /tenement/ {
            proxy_pass http://127.0.0.1:8090/;
			proxy_set_header Host  $host;
           proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
           proxy_set_header X-Real-IP  $remote_addr;
        }
		
		location /station/ {
            proxy_pass http://127.0.0.1:8092/;
			proxy_set_header Host  $host;
           proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
           proxy_set_header X-Real-IP  $remote_addr;
        }
		
		location /cecbill/ {
            proxy_pass http://127.0.0.1:8093/;
			proxy_set_header Host  $host;
           proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
           proxy_set_header X-Real-IP  $remote_addr;
        }
		
		location /inspection/ {
            proxy_pass http://127.0.0.1:8094/;
			proxy_set_header Host  $host;
           proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
           proxy_set_header X-Real-IP  $remote_addr;
        }
		
		location /report/ {
            proxy_pass http://127.0.0.1:8095/;
			proxy_set_header Host  $host;
           proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
           proxy_set_header X-Real-IP  $remote_addr;
        }
		
		location /risk/ {
            proxy_pass http://127.0.0.1:8096/;
			proxy_set_header Host  $host;
           proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
           proxy_set_header X-Real-IP  $remote_addr;
        }

        location /backlog/ {
            proxy_pass http://127.0.0.1:8097/;
			proxy_set_header Host  $host;
           proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
           proxy_set_header X-Real-IP  $remote_addr;
        }
		location /mediacenter/ {
           proxy_pass http://127.0.0.1:8095/;
           proxy_set_header Host  $host;
           proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
           proxy_set_header X-Real-IP  $remote_addr;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

		
		location /sso/ {
           proxy_pass http://sso/;
           proxy_set_header Host  $host;
           proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
           proxy_set_header X-Real-IP  $remote_addr;
        }
		
		location /appmanage/ {
           proxy_pass http://appmanage/;
           proxy_set_header Host  $host;
           proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
           proxy_set_header X-Real-IP  $remote_addr;
        }
	
		
		
    }
	
	upstream sso{
	 server 192.168.30.123:21017 weight=1 ;#server 
    }
     upstream appmanage{ 
    server 10.8.3.37:8086 weight=1 ; //后端服务的ip
    }
}

标签:set,http,header,pass,nginx,proxy,使用,location
From: https://www.cnblogs.com/hxy--Tina/p/16899893.html

相关文章

  • 在 scss 中使用变量
    问题之前二次封装了一个树形组件MenuTree,自定义了节点名。后来优化为:节点名超过一定宽度就显示toolTip样式,即:以省略号显示超出部分内容,只有在鼠标悬浮时才会显示完整内......
  • Nginx负载均衡和动静分离
    一、Nginx负载均衡和动静分离1、Nginx实现负载均衡是通过反向代理实现反向代理(ReverseProxy)是指以代理服务器(例:Nginx)来接受internet上的连接请求,然后将请求转发给......
  • Vue 3.x 中使用 Axios 请求远程Api接口数据
    一、安装axios插件npminstallaxios--save//或者yarnaddaxios//或者cnpminstallaxios--save 注:安装包的时候后面的 --save,如果不加,只安装在当前项目,把......
  • Mac电脑专业编程和数学计算必备工具MATLAB R2022b 完美使用
     mac软件下载:MATLABR2022bforMac怎么安装Mac电脑专业编程和数学计算必备工具MATLABR2022b完美使用资源啊,商业数学软件MATLABR2022更新了,作为数学类科技应用软件......
  • (转)Nginx:04---Nginx的命令行控制
    原文:https://blog.csdn.net/qq_41453285/article/details/106295274在默认的情况下:Nginx安装在/usr/local/nginx/下可执行的Nginx文件为/usr/local/nginx//sbin/nginx默认......
  • nginx高并发优化之缓存配置
    一、配置http{proxy_cache_path/app/cache/levels=1:2keys_zone=proxy_cache:10mmax_size=10ginactive=60muse_temp_path=off;upstreambackend{server127......
  • 如何解决使用 CloudFlare 导致网站 重定向的次数过多的问题
    CloudFlare造成重定向的次数过多的原因当网站开启了CloudFlare服务,Cloudflare再代理用户请求我们的源服务器,以达到加速和保护源服务器的目的。Cloudflare造成循环重定......
  • Python之configparser模块的简单使用
    一、configparser安装pip3installconfigparser二、新建config.ini[ENV]env=QA1[QA1]url=https://qa1-xxx.cns_url=https://qa-s-xxx.cn[QA2]url=htt......
  • 微擎pdo_fetchall中使用in 查询
    有时候我们需要使用MySQL中的in()查询,在微擎中,因为有pdo_系列方法,一般来说,想当然的会像下面这种方式使用:$ids_string='1,2,3';pdo_fetchall("select*from".tablename(......
  • Vue 中 watch 监听器与 computed 计算属性的使用
    一、watch:监视单个属性,可做简单监视和深度监视。根据数据的具体结构,决定是否采用深度监视。配置deep:true可以监测对象内部值的改变,做深度监视时使用。1、简单监视:监视单......