I have a project built in CodeIgniter. In my localhost, the website work fine, but in the remote server, fail the image inclusion from CSS & JS.
The site, is guest in a subdomain. The server file system hierarchy is:
--/
---apps (subdomain folder for my app)
----application
----[other CI forlders]
----css
----js
----img
--[other web folders (no CI)]
--index.html
In CSS files i define the images paths this way: "../img/"
For example:
#maincontainer {background-image: url('../img/main_bg.gif');}
But, in Chrome and FF, show error to load resources:
Failed to load resource: the server responded with a status of 404
(Not Found) http://apps.manantiales.edu.ar/img/main_bg.gif
Any ideas?
You are on a subdomain, therefore, the correct path would be:
http://manantiales.edu.ar/apps/img/main_bg.gif
You can use rules in your htaccess file to make the subdomain path work
or
Just use absolute paths like diEcho suggested. You can embed php code in css files like this:
maincontainer {background-image: url('< ?php echo site_url('img/main_bg.gif');?>');}
(I have put an extraspace at < ?php as not sure how to format it to show correctly here)
You can simply do it like this
--/
---apps (subdomain folder for my app)
----application
----[other CI forlders]
--[other web folders (no CI)]
--index.html
--css
--js
--img
#maincontainer {background-image: url('../img/main_bg.gif');}
and in html files;
<?= base_url();?>css/css.css
Related
I am using Laravel 7.
Location of app.scss : resources/saas/app.scss
Location of app.css : public/css/app.css
In app.scss
background-image: url("../public/images/homeheaderBg.jpg");
on Welcome.blade.php image is not displaying due to wrong Image URL
Wrong Image URL is :
http:localhost/images/homeheaderBg.jpg?325adac1518a8631dcc08fdb07bef837
It should
http:localhost/website_name/images/homeheaderBg.jpg
use
php artisan serve
in your terminal in this way your website link will be
http://localhost:8000
and in this way the right URL will become
localhost/images/homeheaderBg.jpg
im having a hard time to display my static files on my webpages, im hosting my website on digitalocean ubuntu 18 and my static files are stored on the digitalocean space. initially everything was okay and working correctly until i added 3 new images to the server and ran the collectstatic command afterwards, note this was for the second time cause i ran it the first time to store the files in the digitalocean space folder i created. The collectstatic command shown me a warning saying
UserWarning: The default behavior of S3Boto3Storage is insecure and will change in django-storages 2.0. By default files and new buckets are saved with an ACL of 'public-read' (globally publicly readable). Version 2.0 will default to using the bucket's ACL. To opt into the new behavior set AWS_DEFAULT_ACL = None, otherwise to silence this warning explicitly set AWS_DEFAULT_ACL. "The default behavior of S3Boto3Storage is insecure and will change "
after i continue by typing yes, the files are images are successfully stored in the digital-space, but ever since i ran the collect command for the second time all staticfile are not displayed. I did some further reading about this warning and used the solution from AWS S3 and Django returns "An error occurred (AccessDenied) when calling the PutObject operation" but still nothing changed the warning went away but the staticfiles are still not found.
heres the error message from the chrome browser: Failed to load resource: the server responded with a status of 404 (Not Found)
have you ensured your settings display this:
STATIC_ROOT = os.path.join('static')
STATIC_URL = '/static/'
Following this, your templates should show the following:
<link rel="stylesheet" type="text/css" href="{% static '/locationofstatics/css/style.css' %}">
<link rel="stylesheet" type="text/css" href="{% static '/locationofstatics/css/bootstrap.css' %}">
The best way to go about things in my opinion is to only collecstatic locally and then push all of the local files and directories up to the server. What do you currently use to transfer files to the server side?
The other thing you need to do is ensure that Nginx has the location of your static files set within the sites-available file. From your ssh terminal (server side terminal) you can type:
sudo nano /etc/nginx/sites-available/projectname
Within this you need to add the location of your statics, for example:
server {
ocation /static/ {
root /home/name/projectname;
}
}
The following documents are extremely useful:
https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-16-04
https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-ubuntu-18-04
I was using nginx server in digitalocean for my django project.
front-end static files were working but admin not.
See my static files setting:
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static')
]
STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles")
front-end css in static folder and collectstatic target folder is staticfiles
So our main focus is STATIC_ROOT means staticfiles folder. In nginx settings put "staticfiles" instead of "static" to set static file location.
Your STATIC_ROOT folder name could be anything you need to use that same name in nginx.
See below code for nginx setting:
location /staticfiles/ {
root /home/[your_username]/[your_project_folder];
}
[your_username]: which you are using to host your project on digitalocean.
The whole thing is that, you need to use your STATIC_ROOT folder in nginx setting.
Command to create/edit nginx setting is:
sudo nano /etc/nginx/sites-available/[your_project_folder]
Why am I getting the following error when the debug flag in the web.config is set to true?
Mixed Content: The page at 'https://example.com/' was loaded over
HTTPS, but requested an insecure script
'http://example.com/scripts/base/?v=JeAlpXPCZh9gYv4U-X7_HSaAX3Fj3sGBjwukxEaloQU1'.
Bundle
bundles.Add(new ScriptBundle("~/scripts/base").Include(
"~/Scripts/Base/app.module.js",
"~/Scripts/Home/home.controller.js",
"~/Scripts/Home/about.controller.js",
"~/Scripts/App/Common/dictionary.class.js",
"~/Scripts/App/Common/constants.class.js",
"~/Scripts/App/Common/multiselect.directive.js",
"~/Scripts/App/Common/paginationOptions.class.js",
"~/Scripts/App/Common/gridHeight.directive.js",
"~/Scripts/App/Common/utility.service.js",
"~/Scripts/App/Common/dateToString.directive.js",
"~/Scripts/App/Common/base.controller.js",
"~/Scripts/App/Common/messagePopover.controller.js"
));
Generated HTML
<script src="/scripts/base?v=JeAlpXPCZh9gYv4U-X7_HSaAX3Fj3sGBjwukxEaloQU1"></script>
I had a similar issue this morning. I found that the virtual path I had set was the same as the folder structure containing the scripts, once I had renamed the virtual folder path, the script bundle was then being requested over https.
Try changing the script bundle virtual path to;
bundles.Add(new ScriptBundle("~/scripts/applicationBase").Include(
"~/Scripts/Base/app.module.js",
....,
....
));
Hope that helps
I use Silex-Skeleton. Twig layout is present in templates directory (templates/layout.html). I store images in web/img directory (top.jpg). I also use built-in php5.4 server running:
php -S localhost:8000 web/index_dev.php
In templates/layout.html I'd like to use web/img/top.jpg picture. So I put there:
<img src="{{ app.request.basepath }}/img/top.jpg">
But image doesn't show.
I've also tried:
<img src="/img/top.jpg">
<img src="/web/img/top.jpg">
But with no success either.
My controller looks like (index.html extends layout.html):
$app->get('/', function () use ($app) {
return $app['twig']->render('index.html', array());
})->bind('homepage');
What should I do to get images to work?
Can you navigate to http://localhost:8000/web/img/top.jpg or http://localhost:8000/img/top.jpg directly? If you can't browse and see them directly they will not render as the browser will not be able to find them to display on your page either.
Are your images actually in or below the /web folder? (i.e. they should not be in your /templates folder)
Perhaps you could try to set the docroot explicitly sing the -t option when you launch the PHP webserver.
Otherwise I would suggest setting up a real web server like Apache. Your OS may already have this installed if you are running OS X or *nix.
My css files named main.css?v=1.0.0 , site.css?=v.1.0 .
how to configure nginx to serve this kind of files(not extension with .css or .js but with a version number)
FYI:
all the files are in the right path and erro message in chrome dev tool console is file not found(404)
Thanks !
When you're trying to access main.css?v=1.0.0 or main.css?v=2.0.0 any webserver will point it to the same file, main.css
.
Well in your situation coud create a separate location for your versioned file, and then use the next code in the nginx config:
location = /main.css {
if ($arg_v) {
rewrite ([0-9]+) /where/maincss/versions/stored/main-$avg_v.css last;
}
// otherwise default main.css
}
The same thing'll be for the any other file