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)
上一篇 2026年1月15日 下午3:01
下一篇 2026年1月15日 下午3:22


相关推荐

  • Zookeepers_docker workdir

    Zookeepers_docker workdir文章目录Curator客户端创建会话创建节点获取节点和数据更新数据删除节点事务节点存在事件监听其他工具类开发测试Curator客户端Curator包含了几个包:curator-framework:对zookeeper的底层api的一些封装curator-client:提供一些客户端的操作,例如重试策略等curator-recipes:封装了一些高级特性,如:Cache事件监听、选举…

    2025年8月6日
    4
  • Linux之常用命令

    Linux之常用命令2.常用命令2.1命令格式的说明命令格式:命令\[-选项][参数]参数eg:ls-la/usr说明:大部分命令遵从该格式多个选项时,可以一起写eg:ls–l–als–la简化选项与完整选项(注:并非所有选项都可使用完整选项)eg:ls–allls–a帮助命令:(相当于命令说明书)2.2帮助命令2.2.1man英文:…

    2022年5月28日
    37
  • AI Agent(智能体) 教程

    AI Agent(智能体) 教程

    2026年3月14日
    2
  • jvm类的加载机制_java类加载流程及原理

    jvm类的加载机制_java类加载流程及原理1.类加载器的组织结构转载请注明出处:http://blog.csdn.net/seu_calvin/article/details/52301541类加载器ClassLoader是具有层次结构的,也就是父子关系。其中,Bootstrap是所有类加载器的父亲。(1)Bootstrapclassloader:启动类加载器当运行Java虚拟机时,这个类加载器被创建,…

    2022年8月11日
    9
  • 【转】使用 Jmeter 做 Web 接口测试

    【转】使用 Jmeter 做 Web 接口测试

    2022年2月22日
    54
  • mac pro M1(ARM)安装:VMWare Fusion及linux(centos7/ubuntu)(一)

    mac pro M1(ARM)安装:VMWare Fusion及linux(centos7/ubuntu)(一)0.引言最近正好在macM1上安装centos虚拟机以及开发环境,特记录下,以供后续有需要的同学参考1.下载1.1安装VMwareFusion我选择在VMware上运行虚拟机,所以需要下载VMwareFusion下载地址:VMwareFusionforM1选择ARM版本下载,目前是官方推出的针对M1的试用版本,无需激活,后续是否收费还未可知下载后双击安装即可1.2下载centoscentosform1下载地址:centosform1北京外国语大学镜像地址(推荐下

    2022年10月17日
    8

发表回复

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

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