Linux 配置nginx转发路由

Linux 配置nginx转发路由配置 nginx 转发路由 Linux 上首先安装好 nginxLinux 上首先安装好 nginx 进入到 nginx 安装目录 配置文件 cd usr local nginx conf 创建 conf d 文件夹 mkdirconf d 首先更改 nginx conf 文件内容 yamlxml usernobody worker processes1 error loglogs error log error loglogs error logn

配置nginx转发路由

Linux 上安装nginx

yum -y install gcc pcre-devel zlib-devel openssl openssl-devel 
wget https://nginx.org/download/nginx-1.19.9.tar.gz 
解压命令 tar -zxvf nginx-1.19.9.tar.gz 

执行配置

./configure 

#执行命令

make 

#执行make install命令

make install 
 . 进入到nginx安装目录-配置文件 ```powershell cd /usr/local/nginx/conf 
  1. 创建conf.d文件夹
mkdir conf.d 
  1. 首先 更改nginx.conf文件内容
    注意: include /usr/local/nginx/conf/conf.d/*.conf;
#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; include /usr/local/nginx/conf/conf.d/*.conf; default_type application/octet-stream; client_max_body_size 100m; proxy_connect_timeout 300s; proxy_send_timeout 300s; proxy_read_timeout 300s; #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; #} } # server { 
    # listen 9898; # server_name 47.103.159.227:17000; # error_page 404 /index.html; #这个配置,预防页面刷新后跳转到404页面 # location / { 
    # if ($request_method = 'OPTIONS') {  # add_header Access-Control-Allow-Origin *;  # add_header Access-Control-Allow-Methods GET,POST,PUT,DELETE,OPTIONS; # return 204;  # } # root /data1/hecate-rent/dist; # index index.html index.htm; # error_page 404 /index.html; #这个配置,预防页面刷新后跳转到404页面 # location = /50x.html { 
    # root html; # } # } # } # 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; # } #} } 
  1. 在新建的conf.d 文件夹中新建需要配置的项目,比如创建 aa.conf
    注意 :主要是防止页面跳转404
    location / {

    try_files $uri $uri/ /index.html;


add_header Access-Control-Allow-Origin *;
upstream backendTwo {
  server ip:6009;
}

server {
    listen       8013;
    server_name  ip;
    try_files $uri $uri/ /index.html;
    access_log /usr/local/nginx/logs/server.access.log;
    location / {
    try_files $uri $uri/ /index.html;
    	if ($request_method = 'OPTIONS') { 
         	add_header Access-Control-Allow-Origin *; 
         	add_header Access-Control-Allow-Methods GET,POST,PUT,DELETE,OPTIONS;
         	return 204; 
    	}
        
        root   /data1/xxx/dist;
        index  index.html index.htm;
    }
    location ^~/api/ {
        proxy_pass http://ip:6009/;
    }
}
  1. 进入nginx sbin,重启nginx
cd /usr/local/nginx/sbin ./nginx -s reload 
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/231366.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 职业目标的评估与调整_遥感图像目标检测数据集

    职业目标的评估与调整_遥感图像目标检测数据集COCO系列文章:MSCOCO数据集目标检测评估(DetectionEvaluation)(来自官网)MSCOCO数据集人体关键点评估(KeypointEvaluation)(来自官网)MSCOCO数据集输出数据的结果格式(resultformat)和如何参加比赛(participate)(来自官网)MSCOCO官网数据集(百度云)下载,COCOAPI、MASKA……

    2022年10月16日
    8
  • 从单片机到ARM Linux驱动——Linux驱动入门篇

    从单片机到ARM Linux驱动——Linux驱动入门篇大一到大二这段时间里学习过单片机的相关知识,对单片机有一定的认识和了解。如果要深究其原理可能还差了一些火候。知道如何编写程序来点量一个LED灯,改一改官方提供的例程来实现一些功能做一些小东西,对IIC、SPI底层的通信协议有一定的了解,但是学着学着逐渐觉得单片机我也就只能改改代码了(当然有的代码也不一定能改出来)。对于我这种以后只想搬砖的码农来说已经差不多了(仅仅是个人观点),…

    2022年7月14日
    17
  • c语言字符串分割函数「建议收藏」

    c语言字符串分割函数「建议收藏」C语言字符串分割strsep函数用于分解字符串为一组字符串。定义语句为char*strsep(char**stringp,constchar*delim);使用实例:#include<stdio.h>#include<stdlib.h>#include<string.h>intmain(){charstr[]="$GP…

    2022年5月2日
    43
  • pki体系包括_pct体系简介

    pki体系包括_pct体系简介1:PKI的概念        PKI(publickeyinfrastructure),即公钥基础设施,是一种以数字证书机制为基础,依托应用密码学技术(特别是公钥技术,包括加密、签名等应用技术模式)实施并提供安全服务的具体普遍适用性的网络安全基础设施。2:PKI的功能        一个有效的PKI系统必须是安全的和透明的,它的主要目的是通过自动管理密钥和证书,为用户建立起一个安全的

    2022年8月22日
    10
  • 汉澳sinox不受openssl心血漏洞影响并分析修复其漏洞代码

    汉澳sinox不受openssl心血漏洞影响并分析修复其漏洞代码OpenSSL心血(HeartBleed)漏洞是openssl在2014-04-07发布的重大安全漏洞(CVE-2014-0160)这个漏洞使攻击者可以从server内存中读取64KB的数据,甚至获取到加密流量的密钥。用户的名字和password。以及訪问的内容。主要影响版本号OpenSSL1.0.1到OpenSSL1.0.1f以及OpenSSL1.0….

    2022年7月16日
    28
  • java全排列递归算法_java排列组合代码实现

    java全排列递归算法_java排列组合代码实现一、排列1、计算公式如下:2、使用方法,例如在1,2,3,4,5中取3个数排列:3、全排列当m=n时,结果为全排列。例如1,2,3,4的全排列如下:4、代码实现求无重复数组的全排列 /** *循环递归获取给定数组元素(无重复)的全排列 * *@paramoriList原始数组 *@paramoriLen原始数组size *@paramarrayCombResult数组排列结果集,可传null或空Set *@parampreList记录排列参数

    2022年8月31日
    3

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号