P
P
PedroGarciyaLopez2015-09-03 13:10:33
Nginx
PedroGarciyaLopez, 2015-09-03 13:10:33

Nginx, is it possible to "give away" css and js scripts from another directory?

Nginx is on the local machine, purely for development purposes, not production.
Work is underway on two projects, both are in /usr/share/nginx/html, i.e.:
Project 1 lies: в /usr/share/nginx/html/project1
Project 2 lies: в /usr/share/nginx/html/project2
and are available by http://localhost/project1and http://localhost/project2respectively.
js scripts and css are located in the root of the projects projectN/js и projectN/css
simple config:

server {
    listen 80;

    server_name localhost;

    root /usr/share/nginx/html;

   index index.html index.htm index.php;

   location ~* \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
   }

   location /project1/ {
     try_files $uri $uri/ /project1/back/index.php;
   }

   location /project2/ {
     try_files $uri $uri/ /project2/index.php;
   }
}

when requested http://localhost/project1/page1, html is returned, in which the styles are connected like this:
<link href="css/styles.css" rel="stylesheet">
naturally, the browser begins to require them at the address: http://localhost/project1/page1/css/styles.css
Is it possible to configure the configuration so that the server, receiving such requests, searches for css and js where they are?
If so, how?
A huge request not to send me to the manual. I agree that it is better to delve into and figure it out once and for all. But now I'm not up to it. Thank you in advance for your help.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question