最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

nginx部署前端項目location時root和alias配置指南

 更新時間:2024年01月08日 15:53:39   作者:阿松哥哥2018  
nginx指定文件路徑有兩種方式root和alias,下面這篇文章主要給大家介紹了關于nginx部署前端項目location時root和alias配置的相關資料,文中通過代碼介紹的非常詳細,需要的朋友可以參考下

操作說明

1、nginx目錄中html目錄下放置green 前端項目

監(jiān)聽端口:8181

nginx配置文件配置location時使用root方式

	# root 方式
		#  方式1 域名直接可訪問到  即 localhost:8181
		#location / {
        #    root   html;
        #    index  green/index.html green/index.htm;
        #}
		
		#  方式2 域名直接可訪問到  即 localhost:8181
		#location / {
        #    root   html/green/;
        #    index  index.html index.htm;
        #}
		
		#  方式2.1 域名直接可訪問到  即 localhost:8181
		#location / {
        #    root   html/green;
        #    index  index.html index.htm;
        #}

		# 方式3  域名+/green  可訪問到  即 localhost:8181/green
        #location /green/ {
        #    root   html;
        #    index  index.html index.htm;
        #}
		
		# 方式3.1  訪問不到green下任務資源
        #location /green/ {
        #    root   html/green/;
        #    index  index.html index.htm;
        #}

以上三種 方式結論驗證 用root屬性指定的值是要加入到最終路徑中的,匹配條件會拼接到路徑中

即最終獲取的靜態(tài)頁面路徑為:域名 + root + 區(qū)配條件 + index

即找到 localhost:8181/html/green/index.html

備注:方式2 和方式2.1 用于驗證 root 屬性的值最后的 “/“為非必須,有沒有最后一個”/” 都可以訪問到

nginx配置文件配置location時使用alias方式

# alias 方式
		#  方式1  域名直接可訪問到  即 localhost:8181
		#location / {
        #    alias   html/green/;
        #    index  index.html index.htm;
        #}
		
		#  方式1.1  訪問不到green下任務資源
		#location / {
        #    alias   html/green;
        #    index  index.html index.htm;
        #}
		
		#  方式2  域名直接可訪問到  即 localhost:8181
		#location / {
        #    alias   html/;
        #    index  green/index.html green/index.htm;
        #}
		
		#  方式3  域名直接可訪問到  即 localhost:8181/green
		#location /green {
        #    alias   html/green/;
        #    index  index.html index.htm;
        #}
		
		#  方式3.1  域名直接可訪問到  即 localhost:8181/green
		#location /green/ {
        #    alias   html/green/;
        #    index  index.html index.htm;
        #}

以上三種 方式結論驗證 用alias屬性指定的值,匹配條件不會拼接到路徑中,會直接在alias屬性的值下面去找資源

即最終獲取的靜態(tài)頁面路徑為:域名 + alias + index

即找到 localhost:8181/html/green/index.html

備注:方式1 和方式1.1 用于驗證 alias 屬性的值最后的 “/“為必須,沒有最后一個”/” 訪問不到

完整的nginx配置文件如下

#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;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
	
	map $time_iso8601 $logdate{
            '~^(?<ymd>\d{4}-\d{2}-\d{2})' $ymd;
            default 'date-not-found';
    }

    access_log  logs/access-$logdate.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       8181;
        server_name  localhost;

        access_log  logs/access-$logdate.log  main;
		
		# root 方式
		#  方式1 域名直接可訪問到  即 localhost:8181
		location / {
            root   html;
            index  green/index.html green/index.htm;
        }
		
		#  方式2 域名直接可訪問到  即 localhost:8181
		#location / {
        #    root   html/green/;
        #    index  index.html index.htm;
        #}
		
		#  方式2.1 域名直接可訪問到  即 localhost:8181
		#location / {
        #    root   html/green;
        #    index  index.html index.htm;
        #}

		# 方式3  域名+/green  可訪問到  即 localhost:8181/green
        #location /green/ {
        #    root   html;
        #    index  index.html index.htm;
        #}
		
		# 方式3.1  訪問不到green下任務資源
        #location /green/ {
        #    root   html/green/;
        #    index  index.html index.htm;
        #}
		
		# 以上三種 方式結論驗證  用root屬性指定的值是要加入到最終路徑中的,匹配條件會拼接到路徑中
		# 即最終獲取的靜態(tài)頁面路徑為:域名 + root + 區(qū)配條件 + index
		# 即找到 localhost:8181/html/green/index.html
		# 備注:方式2  和方式2.1 用于驗證 root 屬性的值最后的 "/"為非必須,有沒有最后一個"/" 都可以訪問到
		
	
	
		# alias 方式
		#  方式1  域名直接可訪問到  即 localhost:8181
		#location / {
        #    alias   html/green/;
        #    index  index.html index.htm;
        #}
		
		#  方式1.1  訪問不到green下任務資源
		#location / {
        #    alias   html/green;
        #    index  index.html index.htm;
        #}
		
		#  方式2  域名直接可訪問到  即 localhost:8181
		#location / {
        #    alias   html/;
        #    index  green/index.html green/index.htm;
        #}
		
		#  方式3  域名直接可訪問到  即 localhost:8181/green
		#location /green {
        #    alias   html/green/;
        #    index  index.html index.htm;
        #}
		
		#  方式3.1  域名直接可訪問到  即 localhost:8181/green
		#location /green/ {
        #    alias   html/green/;
        #    index  index.html index.htm;
        #}
		# 以上三種 方式結論驗證  用alias屬性指定的值,匹配條件不會拼接到路徑中,會直接在alias屬性的值下面去找資源
		# 即最終獲取的靜態(tài)頁面路徑為:域名 + alias +  index
		# 即找到 localhost:8181/html/green/index.html
		# 備注:方式1  和方式1.1 用于驗證 alias 屬性的值最后的 "/"為必須,沒有最后一個"/" 訪問不到
		

        #  后臺服務; 
        location /fdiagnose/ {
			proxy_ignore_client_abort   on;
			proxy_set_header Host $http_host;
			proxy_set_header X-Real-IP $remote_addr;
			proxy_set_header REMOTE-HOST $remote_addr;
			proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        	proxy_pass http://localhost:9090;
        }
    }
}

附:Nginx 配置中root和alias的區(qū)別分析

root和alias都可以定義在location模塊中,都是用來指定請求資源的真實路徑,比如:

location /i/ {  
    root /data/w3;
}

請求 http://foofish.net/i/top.gif 這個地址時,那么在服務器里面對應的真正的資源

 /data/w3/i/top.gif文件

注意:真實的路徑是root指定的值加上location指定的值 。

而 alias 正如其名,alias指定的路徑是location的別名,不管location的值怎么寫,資源的 真實路徑都是 alias 指定的路徑 ,比如:

location /i/ {  
  alias /data/w3/;
}

同樣請求 http://foofish.net/i/top.gif 時,在服務器查找的資源路徑是: /data/w3/top.gif

其他區(qū)別:

     1、 alias 只能作用在location中,而root可以存在server、http和location中。

     2、 alias 后面必須要用 “/” 結束,否則會找不到文件,而 root 則對 ”/” 可有可無。

總結 

到此這篇關于nginx部署前端項目location時root和alias配置的文章就介紹到這了,更多相關nginx location用root和alias配置內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

  • Nginx將http轉換成https的詳細過程

    Nginx將http轉換成https的詳細過程

    相信大家在現(xiàn)有項目里都會通過https訪問,這篇文章主要給大家介紹了關于Nginx將http轉換成https的詳細過程,文中將實現(xiàn)的方法介紹的非常詳細,需要的朋友可以參考下
    2022-05-05
  • Nginx配置PATHINFO隱藏thinkphp index.php

    Nginx配置PATHINFO隱藏thinkphp index.php

    這篇文章主要介紹了Nginx配置PATHINFO隱藏thinkphp index.php,本文直接給出配置示例,需要的朋友可以參考下
    2015-07-07
  • 啟用Nginx目錄瀏覽功能的方法

    啟用Nginx目錄瀏覽功能的方法

    這篇文章主要介紹了啟用Nginx目錄瀏覽功能的方法,需要的朋友可以參考下
    2014-03-03
  • NGINX詳細下載安裝及使用入門教程

    NGINX詳細下載安裝及使用入門教程

    Nginx是一種高性能的Web服務器軟件,它可以處理大量的并發(fā)連接,并且可以緩存HTTP請求以提高性能,本文給大家介紹NGINX詳細下載安裝及使用入門教程,感興趣的朋友跟隨小編一起看看吧
    2024-10-10
  • Nginx 1.28.0 源碼編譯安裝與自定義網頁部署詳細指南

    Nginx 1.28.0 源碼編譯安裝與自定義網頁部署詳細指南

    本文介紹了Nginx1.28.0的安裝過程,提供了自定義HTML文件部署步驟、安裝后核心目錄說明、常用管理命令、部署前端項目示例等內容,感興趣的朋友跟隨小編一起看看吧
    2026-05-05
  • 關于Nginx配置ssl證書實現(xiàn)https安全訪問

    關于Nginx配置ssl證書實現(xiàn)https安全訪問

    這篇文章主要介紹了關于Nginx配置ssl證書實現(xiàn)https安全訪問,前題條件是擁有服務器與可以解析到該服務器的自己的域名,需要的朋友可以參考下
    2023-04-04
  • nginx源碼分析configure腳本詳解

    nginx源碼分析configure腳本詳解

    這篇文章主要介紹了nginx源碼分析configure腳本詳解的相關資料,需要的朋友可以參考下
    2017-05-05
  • nginx阻止對未綁定域名的訪問方式

    nginx阻止對未綁定域名的訪問方式

    本描述重點講解了Nginx配置中如何阻止未綁定特定域名的訪問,通過設置默認server塊和明確指定server名稱,確保只有合法請求能夠匹配成功,從而避免非法訪問的問題
    2026-05-05
  • 如何使用nginx代理ws或是wss的請求

    如何使用nginx代理ws或是wss的請求

    這篇文章主要為大家詳細介紹了如何使用nginx代理ws或是wss的請求,文中的示例代碼講解詳細,感興趣的小伙伴可以跟隨小編一起學習一下
    2024-11-11
  • Nginx實現(xiàn)前端灰度發(fā)布

    Nginx實現(xiàn)前端灰度發(fā)布

    灰度發(fā)布是一種重要的策略,它允許我們在不影響所有用戶的情況下,逐步推出新功能或更新,通過灰度發(fā)布,我們可以測試新版本的穩(wěn)定性和性能,下面就來介紹一下前端灰度發(fā)布的使用,感興趣的可以了解一下
    2025-03-03

最新評論

车致| 咸宁市| 南投市| 麟游县| 蒲城县| 民权县| 柳林县| 南澳县| 汝州市| 榆社县| 南陵县| 安乡县| 苍溪县| 湖南省| 曲阳县| 巢湖市| 安乡县| 景德镇市| 麟游县| 岳普湖县| 花莲县| 津南区| 米脂县| 阿克| 虹口区| 福鼎市| 平潭县| 兰溪市| 宿松县| 台南市| 东丽区| 舒城县| 万宁市| 岱山县| 喀喇| 桑日县| 老河口市| 绥中县| 宜君县| 葵青区| 九龙城区|