nginx index.html does not update after modification - nginx

Sorry for noob question, I suck at Ubuntu.
I have just installed nginx in a Ubuntu server with:
sudo apt-get update
sudo apt-get -y install nginx
It successfully built. I'm trying to change the index page, so I have modified my /usr/share/nginx/html/index.html, and then tried all of these:
sudo service nginx stop
sudo service nginx start
sudo service nginx restart
But when I refresh the root page on my browser it still shows the old page.
This is what the index.html looks like:
I have checked my /etc/nginx/nginx.conf, but don't find anything particular there.
What could I be missing?

If you had checked vhost, you knowned, root directory is /var/www/html...
vhost is in /etc/nginx/sites-available and /etc/nginx/sites-enabled (sites-enabled is symlink).

The correct configuration file for NGINX on Debian is :
/var/www/html/index.nginx-debian.html
If you update this file, the changes will be reflected immediately, without a start/stop or restart.
sudo service nginx stop
sudo service nginx start
sudo service nginx restart

I have same problem before, then after updating nginx conf by moving 'root' from 'server/location' to 'server', it works well. Nginx config file :
server {
listen 443 ssl;
server_name localhost;
root /usr/share/nginx/html/rdist;
location /user/ {
proxy_pass http://localhost:9191;
}
location /api/ {
proxy_pass http://localhost:9191;
}
location /auth/ {
proxy_pass http://localhost:9191;
}
location / {
index index.html index.htm;
if (!-e $request_filename){
rewrite ^(.*)$ /index.html break;
}
}

Related

stub_status metrics page used in nginx does not show

I have this .conf file for nginx
server {
listen 8080;
server_name _;
location /status {
stub_status;
}
}
After I used it, I have reloaded NGINX and found out that on my_ip:8080/status there is no page. I checked nginx.conf and it has include /etc/nginx/conf.d/*.conf; where my .conf is located originally.
What could be the problem?
The config looks OK.
What version of nginx you are running? Prior to version 1.7.5 directive stub_status required an argument: stub_status on;
Is your nginx built with corresponding module? To be sure, you can run nginx -V command and check if there in --with-http_stub_status_module in listed config parameters. If not, you need to rebuild nginx with this module enabled.
Is your .conf really loaded by nginx? Try to dump whole congfiguration with nginx -T command and check, if your config is present there.

NginX https error (500 Internal Server Error) on CentOS

I'm using 'Oracle Cloud'.
I created a VM(Computer instance) on Oracle Cloud with CentOS 8. And I installed NginX, and it works well when I test it with 'http://mydeal.servername.com'.
To make NginX service with HTTPS, I also installed certbot(Let's Encrypt) and created certificate, using the following command.
sudo certbot --standalone -d mydeal.servername.com certonly
Result files were like below.
Cert : /etc/letsencrypt/live/mydeal.servername.com/fullchain.pem;
Key : /etc/letsencrypt/live/mydeal.servername.com/privkey.pem;
I added http and https to firewall service list like below.
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
And I created test index.html like below.
sudo -i
mkdir /var/www
mkdir /var/www/mydeal
echo "MyDeal at Oracle Cloud" > /var/www/mydeal/index.html
And I created https settings, including http redirection, in /etc/nginx/conf.d/my.conf file.
server {
listen 80;
server_name my.servername.com;
location / {
root /var/www/mydeal;
index index.html;
try_files $uri /index.html;
}
return 301 https://$host$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name mydeal.servername.com;
ssl_certificate /etc/letsencrypt/live/mydeal.servername.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/mydeal.servername.com/privkey.pem;
location / {
root /var/www/mydeal;
index index.html;
try_files $uri /index.html;
}
}
Finally, when I start nginx server with the following command, it works well.
sudo -i
sudo nginx
But, when I start nginx server with the following command, it gives error "500 Internal Server Error" on the browser screen.
sudo systemctl enable nginx
sudo systemctl start nginx
I can not find any differences b/w 2 start procedures.
How I can debug this problem?

Configure Nginx to proxy pass to Gunicorn (working when I visit IP, not working when I visit domain name)

I am trying to configure Nginx to proxy pass to Gunicorn.
My django project can be found at /home/justin/project/jobzumo
Start by creating and opening a new server block in Nginx’s sites-available directory:
sudo nano /etc/nginx/sites-available/jobzumo
Within this file I've entered the following:
server{
listen 80;
server_name 142.93.184.125;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/justin/project;
}
location / {
include proxy_params;
proxy_pass http://unix:/run/gunicorn.sock;
}
}
When I go to 142.93.184.125 I see the default django rocket ship, so I think that means everything is working. However, when I go to 'jobzumo.com' (associated domain), I see the default 'Welcome to nginx!' page.
I know I have both the IP and domain name in my ALLOWED_HOSTS settings and have pointed the domain nameservers at my server. So, do I need to add this domain to this file? The tutorial I was following said either or should do the job. If adding the domain to this file is not what I have to do, can you mention that, so at least I know I'll have to start looking elsewhere. Thanks for any help.
You probably still have the default site in available sites in nginx which is causing the issue. I just had the same problem and the following two commands solved the issue:
sudo unlink /etc/nginx/sites-enabled/default
sudo service nginx restart
if you stopped your gunicorn daemon you might need to restart it and then run the second command above it should do the trick.

Nginx pod not serving css files

I have a webapp running in kubernetes. I want to serve static files, css in my case, from nginx pod. From the application I define css file location like this:
<link rel="stylesheet" href="assets/css/stylesheet.css" type="text/css">
When building docker image I copy over css file to www/media/ and in nginx config I point to that:
FROM nginx
RUN rm /etc/nginx/conf.d/default.conf
COPY config/default.conf /etc/nginx/conf.d/default.template
COPY assets/ /www/media
EXPOSE 80
Here's nginx config:
server {
listen 0.0.0.0:80;
server_name localhost;
location / {
proxy_pass http://${FLASK_APP}:8080/;
}
location ~ /assets {
root /www/media;
}
}
I have confirmed that the file can be found on nginx pod under /www/media/css/stylesheet.css, however I cannot reach it neither from the browser nor the application itself.
The error I get is this:
GET http://192.168.99.106:30604/assets/css/stylesheet.css net::ERR_ABORTED 404 (Not Found)
/assets should point to www/media where the directory with stylesheet are kept, correct?
What am I misunderstanding?
Not sure if this is the solution, but hopefully some things to try.
Change your docker file to
COPY assets /www/media
In your comments you've said that you can see the files in /www/media. But you're trying to access them in /assets. Have you configured this in nginx correctly? Perhaps try this
location /assets/ {
alias /www/media/;
}
Final thing I would mention is permissions. What are the permissions of the files in the container? ls -la will tell you this. They should be 755 I believe for Nignx.
Hope this helps you.
Ok, I figured it out.
Here's my Nginx config to serve the files:
server {
listen 0.0.0.0:80;
server_name localhost;
location / {
proxy_pass http://${FLASK_APP}:8080/;
}
location ~ \.css {
root /www/media;
}
}
I also changed my docker a bit:
FROM nginx
RUN rm /etc/nginx/conf.d/default.conf
COPY config/default.conf /etc/nginx/conf.d/default.template
COPY assets /www/media/assets
RUN chown -R nginx:nginx /www/
EXPOSE 80
With the above config in place css is being served without any issues.

nginx ignores my site configuration

I created site config file in dir /etc/nginx/sites-enabled
server {
listen 80;
server_name domain.com;
gzip_types application/x-javascript text/css;
access_log /var/log/nginx/nodeApp.info9000p.access.log;
location / {
proxy_pass http://127.0.0.1:9000/;
}
location ~ ^/(min/|images/|bootstrap/|ckeditor/|img/|javascripts/|apple-touch-icon-ipad.png|apple-touch-icon-ipad3.png|apple-touch-icon-iphone.png|apple-touch-icon-iphone4.png|generated/|js/|css/|stylesheets/|robots.txt|humans.txt|favicon.ico) {
root /root/Dropbox/nodeApps/nodeApp/9000/appdirectory-build;
access_log off;
expires max;
}
}
and restarted nginx:
sudo /etc/init.d/nginx restart
But nginx ignore my site config file and shows default page, when I request domain.com :
Welcome to nginx!
If you see this page, the nginx web server is successfully installed and working. Further configuration is required.
For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.
Thank you for using nginx.
Where are your Wordpress-files located?
The default nginx htdocs-root is /usr/share/nginx/html
If you've installed the files at, say, /usr/share/nginx/html/wordpress, then you must change the root-setting in the file /etc/nginx/conf.d/default.conf to that directory, like this
server {
root /usr/share/nginx/html/wordpress;
}
Plese read the https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-on-centos-7 article on how to set up nginx to work with the PHP-engine over socket (CentOS) if you have not already done so.
Don't know how, but my configuration started to work well. Maybe because I restarted nginx instead of reload it.

Resources