nginx 反向代理以及 location /admin/

本文介绍了如何在Nginx中配置反向代理,特别关注了location/admin/的处理,强调了在测试阶段的注意事项,并提到了alias与proxy_pass的区别,适用于部署多个PHP项目到同一域名下的场景。
摘要由CSDN通过智能技术生成

nginx 反向代理以及 location /admin/


反向代理时, 需要特别注意,本地测试时确保类似IP调用 127.0.0.1:8082/admin 这种情况可以直接访问,在做反向代理。否则请使用测试域名访问,反向代理才可以成功,最好设置相关header头,跳转的才可以使用。

// 常规
server {
    listen 8280;
    server_name angelsteward.test *.angelsteward.test;
    root "E:/own/git/angelsteward/public/";
    
    index index.html index.htm index.php;
 
    location / {
        try_files $uri $uri/ /index.php$is_args$args;
		autoindex on;
    }
    
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass php_upstream;		
        #fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    }
	
	
    charset utf-8;
	
    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }
    location ~ /\.ht {
        deny all;
    }
}

// 反向代理
server {
    listen 8280;
    server_name angelsteward.test *.angelsteward.test;
 
    location / {
        root "C:\Users\Y\Desktop\18token\18token.im";
		index index.html index.htm index.php; 
		autoindex on;
    }
	
	 location /admin { 
        #alias "E:/own/git/cim/public/"; 
		proxy_pass  http://127.0.0.1:8082;
		proxy_set_header Host $host;
        proxy_set_header  X-Real-IP        $remote_addr;
        proxy_set_header  X-Forwarded-For  $proxy_add_x_forwarded_for;
        proxy_set_header X-NginX-Proxy true;
		#try_files $uri $uri/ /index.php$is_args$args;
        #index index.html index.htm index.php; 
        #autoindex on; 
    } 
    
    location ~ \.php(.*)$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass php_upstream;		
        #fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    }
	
	
    charset utf-8;
	
    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }
    location ~ /\.ht {
        deny all;
    }
}

// ssh 443 https
server {
	listen       4430  ssl;
#	listen       443;
    server_name  angelsteward.test *.angelsteward.test;
#	ssl                  on;
    ssl_certificate      E:\own\git\https\server.pem;
    ssl_certificate_key  E:\own\git\https\privkey.pem;
    ssl_session_timeout  5m;
    ssl_protocols  SSLv2 SSLv3 TLSv1;
    ssl_ciphers  HIGH:!aNULL:!MD5;
    ssl_prefer_server_ciphers   on;
	
	root "E:/own/git/angelsteward/public/";
    
    index index.html index.htm index.php;
 
    location / {
        try_files $uri $uri/ /index.php$is_args$args;
		autoindex on;
    }
    
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass php_upstream;		
        #fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    }
	
	
    charset utf-8;
	
    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }
    location ~ /\.ht {
        deny all;
    }
}

# This file is auto-generated.
# If you want Laragon to respect your changes, just remove the [auto.] prefix
# If you want to use SSL, enable it at: Menu > Nginx > SSL > Enabled

重点 alias 关键字,在此处是通过 / 根目录访问静态网页。/admin 访问 php 项目,此处由于原 laravel 项目域名路由已经定义 admin 路径冲突,只能使用反向代理配置。
这种情况应该是适用于 php 项目已有 /admin 子目录时且已经是适配 /admin 的路由,或者是类似 /api 的路由配置,才可以进行目录跳转适配。否则产生错误404。

即反向代理用户多个不同的项目部署于一个域名下。
alias 用于项目(多个)下的多个模块区分,比如 前后端、api 分离 的路由指定。


在做 https ssh 443 的配置时,暂可以忽略其他配置。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值