導航:首頁 > 版本升級 > nginx多個文件夾

nginx多個文件夾

發布時間:2023-02-23 02:45:37

❶ nginx同域名配置多目錄路徑

server{
server_name xxx.cn;
charset utf-8;
location / {
index index.html index.shtml;
root /web/t; 新路徑
error_page 404 = @not_found;
}

location @not_found {
index index.html index.shtml;
root /web1/t; 老路徑
}

}

❷ 配置伺服器 —— Nginx添加多個二級子域名 --- 2018-06-26

Nginx多文件配置二級子域名(推薦)

首先,在自己的域名控制台中添加解析,這里以添加blog前綴為例

我用的是萬網,在 解析設置 中 添加解析

主機記錄 :你想要的二級域名 

記錄值 :你的IP地址

保存後,我們就完成了第一步把子域名解析到我們的伺服器上。

第二步:添加配置文件

進入nginx的 /conf 配置文件夾中,編輯 nginx.conf 文件

[root@iZ2844brz0xZ~]# cd /usr/local/nginx/conf/[root@iZ2844brz0xZ~]# vim nginx.conf

在 http 模塊中添加如下語句

include/usr/local/nginx/conf/sites-enabled/*.conf;

告訴這個配置文件要去包含 /sites-enabled 目錄下的所有以 .conf 結尾的配置文件。:wq 保存。

此時,我們新建一個 /sites-enabled 文件夾,並在其中添加 blog.***.com.conf 文件

[root@iZ2844brz0xZconf]# mkdir sites-enabled[root@iZ2844brz0xZsites-enabled]# vim blog.***.com.conf

在文件中添加

server {listen80;#監聽埠server_name blog.***.com;#綁定域名root /usr/local/nginx/html/blog/;#網站根目錄,建議使用絕對路徑indexindex.phpindex.htmlindex.htm;#默認文件#添加對php的解析location ~ \.php$ {        fastcgi_pass127.0.0.1:9000;        fastcgi_indexindex.php;        fastcgi_param  SCRIPT_FILENAME$document_root$fastcgi_script_name;        include        /usr/local/nginx/conf/fastcgi_params;    }#添加錯誤頁面,利於搜索引擎收錄以及良好的用戶體驗error_page404/404.html;    location /404.html {        root /usr/local/nginx/html/;    }    error_page500502503504/50x.html;    location =/50x.html {

        root /usr/local/nginx/html/;    }}

內容可自行添加

Nginx單文件配置二級子域名

在 nginx.conf 文件的 server 模塊中添加以下語句

if($host~* (\b(?!www\b)\w+)\.\w+\.\w+ ) { set$subdomain/$1;}location / { root html$subdomain;indexindex.htmlindex.phpindex.htmindex;}

即可解析到對應文件夾

最後,重啟nginx即可

[root@iZ2844brz0xZsites-enabled]# /usr/local/nginx/sbin/nginx -s reload

來自:https://blog.csdn.net/LBinin/article/details/70188752

❸ nginx命令如何把多個文件壓縮到一個文件夾

目前應該是做不到,有一個順序的,比如烏鴉喝水,要想喝到水,必須把東西放進瓶子了,然後水就滿上來,只有滿上來,才可以喝到水,你也一樣,竟然都是壓縮文件,你可以將壓縮包全部選中,記住是壓縮包,不能是別的文件,選擇以後進行解壓到當前的目錄,這樣的話,大部分的圖片會呈現在我們的目錄下,也許有些壓縮包裡面還有根目錄,創建文件夾,利用索引圖片格式,把所有的圖片放你創建的文件下,然後對有根目錄的文件進行二次處理,這樣會好一下,目前我只能想這樣的解決方案,畢竟我不能夠保證你某個壓縮包下的文件目錄級別是幾個,如果都是同一級的目錄,就好解決了,希望方案能夠給你解決問題

❹ Nginx 使用多個.conf文件配置多個虛擬主機server的方法

一般Nginx的配置都默認在 /usr/local/etc/nginx/nginx.conf 里,但是如果我們有多個虛擬主機需要配置的話,全部寫在 nginx.conf 下會很臃腫,因此呢, Nginx 提供 include 包含其他配置文件的方式幫助我們解決這個問題,接下來我們就來看看具體怎麼配置

安裝好 Nginx 後,其默認配置文件不需要更改,它已經幫我們導入了其他配置文件的目錄,如上圖,最後一句 include servers/*; ,意思就是該配置文件包含 nginx.conf 的同級目錄下的 servers 文件夾下所有的文件,這時候我們只需要在 nginx.conf 的同級目錄下創建一個 servers 的文件夾,然後創建自己的 .conf 文件就行,當然,如果你的配置文件是其他目錄,就修改 include 後的路徑就可以

xxx.conf 中的只需要寫 server 塊就行,其實就相當於把這個 server 塊添加到 nginx.conf 中的 http 塊中

重啟 nginx
sudo nginx -s reload

❺ nginx部署多個前後端項目

http://127.0.0.1/helloworld    第一個vue項目(不用修改配置直接build就可以)

http:// 127.0.0.1 /test02   第二個vue項目(需要修改)

1、首先在config文件夾內的index.js內修改(注意是build內)

build: {

    // Template for index.html

    index: path.resolve(__dirname, '../dist/index.html'),

    // Paths

    assetsRoot: path.resolve(__dirname, '../dist'),

    assetsSubDirectory: 'static',

    //nginx配置

    assetsPublicPath: '/test2/',

    /**

    * Source Maps

    */

    proctionSourceMap: true,

    // https://webpack.js.org/configuration/devtool/#proction

    devtool: '#source-map',

    // Gzip off by default as many popular static hosts such as

    // Surge or Netlify already gzip all static assets for you.

    // Before setting to `true`, make sure to:

    // npm install --save-dev compression-webpack-plugin

    proctionGzip: false,

    proctionGzipExtensions: ['js', 'css'],

    // Run the build command with an extra argument to

    // View the bundle analyzer report after build finishes:

    // `npm run build --report`

    // Set to `true` or `false` to always turn it on or off

    bundleAnalyzerReport: process.env.npm_config_report

  }

}

2、這樣確保生產出來的文件,在index.html中都是在student下。對index.html文件進行修改,添加base href="/test2/" >

<!DOCTYPE html>

<html>

<head>

    <!--新添加的-->

    <base href="/test2/" >

    <meta charset=utf-8>

    <meta name=viewport content="width=device-width,initial-scale=1">

    <title>test1</title>

    <link href=/test2/static/css/app..css rel=stylesheet>

</head>

<body>

<div id=app></div>

<script type=text/javascript src=/test2/static/js/manifest.a96262ba9edf9a4c5761.js></script>

<script type=text/javascript src=/test2/static/js/vendor.a6129cab87d1dbebc84c.js></script>

<script type=text/javascript src=/test2/static/js/app.4694a2e388440c566511.js></script>

</body>

</html>

3、在src/router/index.js文件修改,添加 base: '/test2/'

import Vue from 'vue'

import Router from 'vue-router'

import HelloWorld from '@/components/HelloWorld'

Vue.use(Router)

export default new Router({

  base:"/test2/",

  mode:"history",

  routes: [

    {

      path: '/',

      name: 'HelloWorld',

      component: HelloWorld

    }

  ]

})

user root;

worker_processes  1;  #nginx進程個數

#worker_cpu_affinity 1000 0100 0010 0001;  #綁定worker進程到指定的CPU內核中

#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;  #worker進程的最大連接數是1024

}

http {

    #include      mime.types;

    # include /etc/nginx/conf.d/*.conf;

    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"';

    #access_log  logs/access.log  main;

    sendfile        on;

    #tcp_nopush    on;

    #keepalive_timeout  0;

    keepalive_timeout  65;

    upstream rest{

    least_conn;

    server 127.0.0.1:8000;

    server 127.0.0.1:8001;

}

    #gzip  on;

    server {

        listen      80;

        server_name  127.0.0.1;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        #vue第一個項目

      location / {

            root  /usr/local/nginx/projects/dist;

            try_files $uri $uri/ @router;

            index  index.html index.htm;

        }

        #vue第二個項目

        location /test2 {

            alias /usr/local/nginx/projects/test2/;

            try_files $uri $uri/ /test2/index.html;

            index  index.html index.htm;

        }

        location @router {

    rewrite ^.*$ /index.html last;

}

#vue第一個項目後端介面

        location /api_a {

            #轉發到後端uwsgi

                  proxy_pass http://127.0.0.1:5002;

                # 設置請求頭,並將頭信息傳遞給伺服器端

                  proxy_set_header Host $host;

                # 設置請求頭,傳遞原始請求ip給 gunicorn 伺服器

                  proxy_set_header X-Real-IP $remote_addr;

                  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

                #                                                                   

        }

#vue第二個項目後端介面

        location /api_b {

            #轉發到後端uwsgi

                  proxy_pass http://127.0.0.1:5003;

                # 設置請求頭,並將頭信息傳遞給伺服器端

                  proxy_set_header Host $host;

                # 設置請求頭,傳遞原始請求ip給 gunicorn 伺服器

                  proxy_set_header X-Real-IP $remote_addr;

                  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

                #                                                                   

        }

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

        }

    }

}

❻ 5,nginx 多域名,配置多個conf 文件

nginx下配置多域名,目前的配置方法採用多個配置文件的方法比較多

1,在nginx安裝的目錄下找到, nginx.conf文件
如我的: C:\Program Files\nginx-1.15.5\conf 目錄下

2,在該目錄下創建的文件夾,如 vhost 文件夾
C:\Program Files\nginx-1.15.5\conf\vhost

3,在vhost 文件夾下創建 *.conf 文件 如host.conf
C:\Program Files\nginx-1.15.5\conf\vhost\host.conf

4,編輯conf文件,把我們平常放在nginx.conf里的server{......}段直接粘貼到conf里。
如:

5,最後在nginx.conf的http{....}段中加入
include vhost/*.conf;

6,如果有其他的conf文件要添加直接在 按照步驟三操作即可

❼ nginx根目錄設置到其他文件夾

nginx伺服器綁定域名以及設置根目錄非常方便,首先進入nginx安裝目錄,然後執行 vim conf/nginx.conf 打開nginx的配置文件,找到
server {
.....
}
這個代碼段,這段代碼就是用來配置對應站點的,首先我們應該在域名控制面板將域名解析到我們伺服器的IP地址,然後綁定才可以生效。《linux就該這么學》一起學習linux
首先在我們的代碼段中找到server_name這一項然後把後面的域名改成我們要綁定的域名即可
root這一項就是指定的根目錄,設置成我們指定的目錄即可.
上配置:
server {
listen 80;
server_name localhost;

root /.../tomcat*/../ ; # 設置root目錄 運行nginx的用戶有許可權。

location / {
index index.html index.htm;
}

}

閱讀全文

與nginx多個文件夾相關的資料

熱點內容
maya粒子表達式教程 瀏覽:84
抖音小視頻如何掛app 瀏覽:283
cad怎麼設置替補文件 瀏覽:790
win10啟動文件是空的 瀏覽:397
jk網站有哪些 瀏覽:134
學編程和3d哪個更好 瀏覽:932
win10移動硬碟文件無法打開 瀏覽:385
文件名是亂碼還刪不掉 瀏覽:643
蘋果鍵盤怎麼打開任務管理器 瀏覽:437
手機桌面文件名字大全 瀏覽:334
tplink默認無線密碼是多少 瀏覽:33
ipaddgm文件 瀏覽:99
lua語言編程用哪個平台 瀏覽:272
政采雲如何導出pdf投標文件 瀏覽:529
php獲取postjson數據 瀏覽:551
javatimetask 瀏覽:16
編程的話要什麼證件 瀏覽:94
錢脈通微信多開 瀏覽:878
中學生學編程哪個培訓機構好 瀏覽:852
榮耀路由TV設置文件共享錯誤 瀏覽:525

友情鏈接