欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

nginx部署前端項(xiàng)目location時(shí)root和alias配置指南

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

操作說明

1、nginx目錄中html目錄下放置green 前端項(xiàng)目

監(jiān)聽端口:8181

nginx配置文件配置location時(shí)使用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下任務(wù)資源
        #location /green/ {
        #    root   html/green/;
        #    index  index.html index.htm;
        #}

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

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

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

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

nginx配置文件配置location時(shí)使用alias方式

# alias 方式
		#  方式1  域名直接可訪問到  即 localhost:8181
		#location / {
        #    alias   html/green/;
        #    index  index.html index.htm;
        #}
		
		#  方式1.1  訪問不到green下任務(wù)資源
		#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;
        #}

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

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

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

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

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

        #  后臺服務(wù); 
        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模塊中,都是用來指定請求資源的真實(shí)路徑,比如:

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

請求 http://foofish.net/i/top.gif 這個(gè)地址時(shí),那么在服務(wù)器里面對應(yīng)的真正的資源

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

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

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

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

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

其他區(qū)別:

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

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

總結(jié) 

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

相關(guān)文章

  • nginx配置錯(cuò)誤日志的實(shí)現(xiàn)步驟

    nginx配置錯(cuò)誤日志的實(shí)現(xiàn)步驟

    配置nginx代理過程中,如果出現(xiàn)錯(cuò)誤,需要看日志,可以把nginx日志配置出來,以便快速定位日志問題,下面就來介紹一下nginx配置錯(cuò)誤日志的實(shí)現(xiàn)步驟,感興趣的可以了解一下
    2025-08-08
  • nginx中的路徑匹配location規(guī)則詳解

    nginx中的路徑匹配location規(guī)則詳解

    Nginx的匹配規(guī)則用location指令來實(shí)現(xiàn),Nginx 的location指令用于匹配請求的 URI(請求路徑),并根據(jù)匹配結(jié)果執(zhí)行特定的處理指令,這篇文章主要介紹了nginx中的路徑匹配規(guī)則詳解(location規(guī)則),需要的朋友可以參考下
    2025-04-04
  • 詳解Nginx中HTTP的keepalive相關(guān)配置

    詳解Nginx中HTTP的keepalive相關(guān)配置

    這篇文章主要介紹了Nginx中HTTP的keepalive相關(guān)配置,以及Nginx的Httpd守護(hù)進(jìn)程相關(guān)的keepalive timeout配置,需要的朋友可以參考下
    2016-01-01
  • Nginx 中文域名配置詳解及實(shí)現(xiàn)

    Nginx 中文域名配置詳解及實(shí)現(xiàn)

    這篇文章主要介紹了Nginx中 文域名配置詳解及實(shí)現(xiàn)的相關(guān)資料,Nginx虛擬主機(jī)上綁定一個(gè)帶中文域名但是不能跳轉(zhuǎn),這里給大家說下如何實(shí)現(xiàn),需要的朋友可以參考下
    2016-12-12
  • nginx禁止訪問.git文件的設(shè)置教程

    nginx禁止訪問.git文件的設(shè)置教程

    這篇文章主要介紹了nginx禁止訪問.git文件的設(shè)置教程,.git文件會包含一份文件列表,如果你的網(wǎng)站是基于git協(xié)作開發(fā)的,則必須要注意這個(gè)問題,需要的朋友可以參考下
    2014-08-08
  • Nginx多層代理配置方法

    Nginx多層代理配置方法

    這篇文章主要介紹了Nginx多層代理配置方法,此篇文章只給大家介紹nginx的多級代理配置代碼,需要的朋友可以參考下
    2017-08-08
  • nginx完全卸載的方法步驟

    nginx完全卸載的方法步驟

    由于現(xiàn)在nginx有版本漏洞,所以很多安裝過nginx的需要卸載重新安裝,本文主要介紹了nginx完全卸載的方法步驟,具有一定的參考價(jià)值,感興趣的可以了解一下
    2024-08-08
  • WinPC搭建nginx服務(wù)器的實(shí)現(xiàn)步驟

    WinPC搭建nginx服務(wù)器的實(shí)現(xiàn)步驟

    本文主要介紹了WinPC搭建nginx服務(wù)器的實(shí)現(xiàn)步驟,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-01-01
  • nginx鏡像構(gòu)建的知識點(diǎn)及方法步驟詳解

    nginx鏡像構(gòu)建的知識點(diǎn)及方法步驟詳解

    這篇文章主要為大家介紹了nginx鏡像構(gòu)建的知識點(diǎn)詳解,<BR>有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-08-08
  • 配置nginx訪問本地靜態(tài)資源,本地圖片,視頻教程

    配置nginx訪問本地靜態(tài)資源,本地圖片,視頻教程

    文章介紹了如何配置Nginx以訪問本地靜態(tài)資源、圖片和視頻,首先,進(jìn)入Nginx安裝目錄并打開`nginx.conf`文件,添加一個(gè)新的`server`配置來指定本地路徑,然后,通過命令行重啟Nginx服務(wù)以應(yīng)用更改,最后,通過瀏覽器訪問配置的圖片路徑來驗(yàn)證配置是否成功
    2025-01-01

最新評論