Flask and Nginx: css not recognized - html

I am trying to deploy my website using Flask. Everything is working perfectly locally (localhost:5000), but when I deploy it on my distant linux ubuntu server (www.linode.com) I encouter a problem. I have installed gunicorn and nginx, but my CSS files are not taken into account, thus, my webpage just appears as an HTML content alone, without shape/colors and so on.
I am very new at web development, and I don't understand why it works perfectly locally and not anymore (not totally) on the linux server. Is the problem related to the nginx that can't manage to do the link between HTML and CSS? Because locally I don't need to use nginx, and everything works.
Here is my nginx config file for when I type sudo nano /etc/nginx/sites-enabled/assets:
server {
listen 80;
server_name 45.79.250.111;
include /etc/nginx/mime.types;
location /static {
alias /home/gardy/ladybird_site/assets/static;
}
location / {
proxy_pass http://localhost:8000;
include /etc/nginx/proxy_params;
proxy_redirect off;
}
}
And here is my website directory tree:
ladybird_site/
requirements.txt
run.py
assets/
__init__.py
config.py
models.py
fonts/
et-line.eot
...
fontawesome-webfont.woff2
main/
routes.py
__init__.py
templates/
index.html
layout.html
static/
css/
animate.css
bootstrap.min.css
font-awesome.min.css
style.css
bxslider/
jquery.bxslider.css
images/
bx_loader.gif
controls.png
et-line-font/
style.css
magnific-popup/
magnific-popup.css
owl-carousel/
owl.carousel.css
owl.theme.css
owl.transitions.css
images/
ldb_ico.ico
founder_pics/
custom_pics/
f1.jpg
f2.jpg
f3.jpg
ldb_imgs/
1.png
2.png
3.png
js/
bootstrap-hover-dropdown.min.js
bootstrap.min.js
...
jquery.bxslider.min.js
main.js
I am getting crazy with that stuff, trying and modifying things since two days without significant improvments, and found no answers on the internet...
Thanks a lot

Your static path looks fine. You have set your server to listen to port 80, which is the default port for HTTP, but maybe you have not opened it. The next step is for you to open it.
sudo ufw allow http/tcp
You mention that your server is still listening to port 5000. However, if you are done with testing, you can disallow this port from being used by Nginx.
sudo ufw delete allow 5000
Enable these new rules by running the command below:
sudo ufw enable
# Hit 'y' for 'yes' when prompted
Finally, you can now restart your Nginx server:
sudo systemctl status nginx.service
If you navigate to your application's IP address, and append static/css/style.css, you should be able to access your CSS file. I mean http://<your IP address>/static/css/style.css

Related

Virtualhost url not found

I installed LAMP on a new EC2 server and via the public IP address I can see the default Ubuntu webpage as loaded by my new apache server.
My problems began when I created a new directory, simply called test, alongside the original html directory. In test, I created index.html with the content "Test page responding and loading ...".
So, I then copy /etc/apache2/sites-available/000-default.conf to test.conf and set DocumentRoot /var/www/test.
I enabled the virtualhost by sudo a2ensite test.conf and restarted the server with sudo service apache2 reload.
In my browser, when I visit the IP address I get the ubuntu page as loaded by apache. I then append /test to the end of the IP address and I get a Not found: The requested URL /test was not found on this server. error.
I disabled the 000-default.conf virtualhost, just out of curiosity, and restarted the server. My output from test/index.html loads in a browser using just the IP address - which I did not expect.
ServerAdmin webmaster#localhost
DocumentRoot /var/www/test
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
I'm trying to simply serve test/index.html when I visit .../test in my browser.
If you don't want Apache to select the default virtual host (the first one for a given host+port) you'll need to use ServerName or ServerAlias in your added virtual host to make sure it matches the hostname/address you're using in the browser.
apachectl -S will summarize your vhosts.

nginx does not use modified index file

I installed nginx on my raspberry pi, and configured it.
However, it does not work as what I want.
The IP of raspberry pi is 192.168.0.182, so I made index.html fil and typed in my browser. But, it show nginx's default message, not my index.html.
If I use 192.168.0.182/index.html, it shows my index.html.
What I want it not to use "/index.html" after IP address for index.html. How shoud I configure nginx?
This is my nginx configuration in /etc/nginx/site-available.
server{
listen 80;
root /home/xaliver/Web/www;
index index.html index.htm;
}
and I linked it by
sudo ln -s /etc/nginx/site-available/mysite /etc/nginx/site-enalbled/
Also, I putted index.html in /home/xaliver/Web/www/. The index.html is
"Hello World"
Please, let me know what I missed.
Thank you.

execute index.html on internet access to server

I'm running Apache on Ubuntu 14.04. I'm Port Forwarding 8080 to my server. I've edited ports.conf to Listen 8080. I have an index.html in /var/www/html. when I browse to MyURL:8080 I get An Index of / that shows html as a directory.
If I click the html directory icon, my index.html executes. I looked at /etc/apache2/sites-available/default-ssl.conf and 000-default.conf, they both show DocumentRoot /var/www/html. So does sites-enabled/000-default.conf.
Any help on what to try next to get the index.html to execute on entry to the server would be appreciated.
I'm by no means an expert on ubuntu's apache configuration, but through some quick searching I found this http://www.ajopaul.com/2010/05/01/ubuntu-apache2-change-default-documentroot-varwww/
Is it necessary to have a trailing "/" on the document root path?

Apache2: Index.html Loads on IP but not on Domain Name (Ubuntu)

I made an AWS EC2 Instance and get an Elastic IP.
The Elastic IP was used to set a Domain Name (Bought from GoDaddy) to the AWS EC2 Instance.
The EC2 Instance is running an Apache2 server.
According to the manual, I'm supposed to replace index.html in /var/www/html/ with the index.html of my own, which I did.
When I use the Elastic IP, the index.html page that I set is displayed.
However when I use the Domain Name, for some reason it gives me the default apache2 page, even though that file no longer exists since it was overwritten. I can access the index.html with DomainName.in/index.html.
Simply put :
- DomainName.in gives apache2 default index.html which shouldn't exist anymore
- DomainName.in/index.html gives the page that I want to show up
- ElasticIP and ElasticIP/index.html both give the page I want to show up
How can I make it so that just typing the Domain Name in the browser will take me to the index.html page that I want it to go to ?
You need to set DirectoryIndex in your virtualhost configuration which is located here: /etc/apache2/apache2.conf
If that is not where your config file is located, you can find it by running: /usr/sbin/apache2 -V | grep SERVER_CONFIG_FILE
<virtualhost *:80>
ServerName domain.com
ServerAlias www.domain.com
# Index file and Document Root (where the public files are located)
DirectoryIndex home.html index.html
DocumentRoot /var/www
</virtualhost>
Ok so it turns out everything is fine, but the changes take time to propagate through the DNS for some reason.
The changes register after about half an hour.

Digital Ocean HTML Files Uploaded Not Working

I have uploaded some html files to my Digital Ocean droplet, on directory /var/www/html, but apparently I still can't connect to http://vps-ip-address, how can I make those files work on default http port when simply typing http://vps-ip-address? I know I'm missing something out and it's probably a newbie mistake, so if someone could explain to me how it can be done, I would be grateful.
By default on Ubuntu, the document root for Nginx is located at /usr/share/nginx/html In order to serve content from /var/www/html you will need to edit your Nginx configuration. The default configuration file is /etc/nginx/sites-enabled/default
Find the line:
root /usr/share/nginx/html;
and change it to:
root /var/www/html;
Then restart Nginx with sudo service nginx restart