日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

nginx 反向代理以及 location /admin/

作者:Blau 更新時間: 2022-10-14 編程語言

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 的配置時,暫可以忽略其他配置。

原文鏈接:https://blog.csdn.net/weixin_43930641/article/details/123066255

欄目分類
最近更新