search

Home  >  Q&A  >  body text

Can nginx directly respond to serve static pages? Why has it been configured unsuccessfully for a long time?

Background: Recently I wanted to write something and put it online. I bought a domain name and a vps, and also set up an ngxin server on the vps. I wanted to start with the simplest static page, so I wrote it myself. A static page index.html is uploaded to the /home/peng/var/www directory through ftp, and then the server node is configured under the http node of the nginx.conf file:

server {
    listen      80 ;
    server_name  **.**.**.**;
    index index.html;
    root /home/peng/var/www;
   }

Finally restarted the nginx service,

But the problem is
Every time I access the domain name address, the nginx welcome page is always returned, as if the configuration has not taken effect at all
The domain name address is: ethanvae.com

This is my first time using nginx, so the question may be very simple. I want to understand it.
1) My idea: return static files directly through nginx. Is this idea feasible? Is it wrong?
2) Are there any good tutorials that start from practice and go into depth about what nginx is, its features, usage scenarios, etc.

Although the question is very simple, I have been confused for an nginx novice for a day
Thank you again for those who can answer

The entire nginx.conf configuration file is as follows

user www-data;
worker_processes 4;
pid /run/nginx.pid;
events {
        worker_connections 768;
        # multi_accept on;
}
http {
        ##
        # Basic Settings
        ##

        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;
        # server_tokens off;

        # server_names_hash_bucket_size 64;
        # server_name_in_redirect off;

        include /etc/nginx/mime.types;
        default_type application/octet-stream;
        server {
          listen      80 ;
          server_name  ethanvae.com;
          location / {
            index index.html;
            root /home/peng/var/www;
          }
        }
        ##
        # Logging Settings
        ##

        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;

        ##
        # Gzip Settings
        ##

        gzip on;
        gzip_disable "msie6";

        # gzip_vary on;
        # gzip_proxied any;
}
给我你的怀抱给我你的怀抱2754 days ago553

reply all(4)I'll reply

  • ringa_lee

    ringa_lee2017-05-16 17:22:49

    In your servermodule add:

    location / {
            root /home/peng/var/www;
            index  index.html index.htm;
        }

    reply
    0
  • 为情所困

    为情所困2017-05-16 17:22:49

    nginx supports static HTML web pages by default.
    Bind the IP with the ethanvae.com domain name provider (resolution may take time, ping at any time to see if it is successful)
    server_name then write ethanvae.com www.ethanvae.com two domain names
    Explanation: Restart after changing the nginx configuration file nginx only takes effect
    You may encounter other problems, explain them in the comments, and I will help you solve them when I am online.

    reply
    0
  • 迷茫

    迷茫2017-05-16 17:22:49

    The original poster’s problem is the lack of location configuration.
    The following is a simple configuration of one of my sites. I’ll send it to you for reference. It may be useful.
    server{

    listen 80;
    server_name www.abc.xyz abc.xyz;
    root /home/name/abc;
    
    location / {
        proxy_set_header Host $host:$server_port;
        proxy_pass http://127.0.0.1:6001;
    }

    }
    server{

    listen 80;
    server_name img0.abc.xyz;
    root /home/name/abc;
    
    location ~ /static/.*\.(css|doc|eip|exe|gif|ico|jpg|js|mp3|png|swf|xml|txt|bm)$ {
        expires 7d;
    }
    

    }

    reply
    0
  • 黄舟

    黄舟2017-05-16 17:22:49

    Visually, the file has not been corrected.

    Run sudo nginx -t 看看打印出来的配置文件是哪个,修改那个,然后再 sudo nginx -s reload and try it.

    Also, take a look at nginx’s access_log and error_log. Check to see what errors are reported and whether there have been any requests.

    reply
    0
  • Cancelreply