主题文件的Nginx位置别名

我正试图将我的主题文件移到文档根目录之外。 我正在使用nginx的服务器,我已经尝试在位置块中使用别名和根指令。 没有我试过的作品,我怀疑这是try_files指令里面的location / 。 我在/var/www/naturesflowllc/ui/assets文件夹中有我的主题文件

这是我的nginx conf文件。

 server { listen 80; listen [::]:80; server_name my.beupnow.dev.kahunacoding.com; root /var/www/naturesflowllc/mybeupnow/public_html; index index.php index.html index.htm; location / { try_files $uri $uri/ /index.php$is_args$args; } location ~ \.php$ { try_files $uri /index.php =404; fastcgi_read_timeout 180; fastcgi_pass php-upstream; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } location /assets/ { alias /var/www/naturesflowllc/ui/assets/; # root /var/www/naturesflowllc/ui/; autoindex off; # autoindex on; } location ~ /\.ht { deny all; } error_log /var/www/naturesflowllc/application/logs/my_beupnow_error.log debug; access_log /var/www/naturesflowllc/application/logs/my_beupnow_access.log; location = /favicon.ico { access_log off; log_not_found off; } location = /robots.txt { access_log off; log_not_found off; } } 

我已经试过aliasrootautoindex开关closures似乎没有工作。

编辑 :所以我想让我的资产像这样服务:

<link href="/assets/global/plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css" />

和这个:

<script src="/assets/global/plugins/jquery.min.js" type="text/javascript"></script>

从我的ui文件夹,这是这样的:

 |____assets | |____apps | | |____css | | | |____inbox.css | | | |____inbox.min.css | | | |____ticket.css | | | |____ticket.min.css | | | |____todo-2.css | | | |____todo-2.min.css | | | |____todo.css | | | |____todo.min.css | | |____img | | |____scripts | | | |____calendar.js | | | |____calendar.min.js | | | |____inbox.js | | | |____inbox.min.js | | | |____todo-2.js | | | |____todo-2.min.js | | | |____todo.js | | | |____todo.min.js | |____global | | |____css | | | |____components-md.css | | | |____components-md.min.css | | | |____components-rounded.css | | | |____components-rounded.min.css | | | |____components.css | | | |____components.min.css | | | |____plugins-md.css | | | |____plugins-md.min.css | | | |____plugins.css | | | |____plugins.min.css | | |____img | | | |____accordion-plusminus.png | | | |____ajax-loading.gif | | | |____ajax-modal-loading.gif | | | |____datatable-row-openclose.png ... (truncated) 

我想从这里删除资产文件夹/var/www/naturesflowllc/mybeupnow/public_html并将其重定位到/var/www/naturesflowllc/ui/assets/

我希望这能澄清我正在努力实现的目标。

编辑 :我只浪费了几个小时才发现我正在编辑错误的nginx.conf文件8(。工作就像它应该与rootalias

https://nginx.ru/en/docs/http/ngx_http_core_module.html#alias位置匹配指令值的最后部分时&#xFF1A;

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

而不是使用root指令:

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

这是你的情况。


我为你创build一个例子,并在我的Ubuntu上尝试:

 server { listen 80; server_name 127.0.0.1; root /tmp/www/; # 1s location location / { try_files $uri $uri/ /index.php; } # 2nd location location ~ \.php$ { proxy_pass http://127.0.0.1:8080; } #3d location location /assets/ { root /tmp/somedir/; } } 

http://127.0.0.1/ – 第一个位置(在/ tmp / www中search索引文件),然后是第二个位置,因为我的/ tmp / www中没有索引文件“

http://127.0.0.1/assets/some.js – “3d location(returns /tmp/somedir/assets/some.js)”

它适用于我与nginx 1.10.3。 如果不适合你,那么请提供你的nginx访问和错误日​​志。