Question

I found my new index.html is /usr/share/nginx/html instead var/www/html.

Posted April 21, 2021 1.1k views
Nginx

I just use ‘sudo restart’ because in command prompt alert 'New version require to restart’.After use sudo restart, my website show 'Welcome to nginx!’. I found my new index.html is /usr/share/nginx/html instead var/www/html. The new location can’t open localhost. I want to redirect it.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
Submit an Answer
1 answer

Hi @sittiphansittisak,

You can update any of your settings from your nginx configuration files. You can find them at /etc/nginx.

As far as I understand, you are using your IP address to open your website, is that correct, or are you using your domain name?

If you are using your IP Address to open our website, what I suggest is to open your default configuration file, which you can find at /etc/nginx/sites-enabled/ and edit the root path so that it looks at the proper directory.

If you are using a domain name, you can again take a look at /etc/nginx/sites-enabled/ however the file should be YourDomain.conf from there you can make your changes.

Don’t forget to restart Nginx afterward

service nginx restart
  • Thank you for your help.
    I use the domain name.
    So, I should copy the file ‘default’ in sites-available to sites-enabled with MyDomainName.conf, right?
    (In the sites-available has file 'default’ but in the sites-enabled has folder 'default’.)

    After I tried to service nginx restart. I have alert:
    Job for nginx.service failed because the control process exited with error code.
    See “systemctl status nginx.service” and “journalctl -xe” for details.

    What I should do next. Thank you.

    • I try to change name of default folder in sites-enabled to MyDomainName.conf. Now, I can run service nginx restart but my page still show Welcome to nginx! and can’t open localhost.

  • My nginx.conf

    user www-data;
    worker_processes auto;
    pid /run/nginx.pid;
    include /etc/nginx/modules-enabled/*.conf;
    
    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;
    
        ##
        # SSL Settings
        ##
    
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
        ssl_prefer_server_ciphers on;
    
        ##
        # Logging Settings
        ##
    
        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;
    
        ##
        # Gzip Settings
        ##
    
        gzip on;
    
        # gzip_vary on;
        # gzip_proxied any;
        # gzip_comp_level 6;
        # gzip_buffers 16 8k;
        # gzip_http_version 1.1;
        # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
    
        ##
        # Virtual Host Configs
        ##
    
        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;
    }
    
    
    #mail {
    #   # See sample authentication script at:
    #   # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
    # 
    #   # auth_http localhost/auth.php;
    #   # pop3_capabilities "TOP" "USER";
    #   # imap_capabilities "IMAP4rev1" "UIDPLUS";
    # 
    #   server {
    #       listen     localhost:110;
    #       protocol   pop3;
    #       proxy      on;
    #   }
    # 
    #   server {
    #       listen     localhost:143;
    #       protocol   imap;
    #       proxy      on;
    #   }
    #}
    

    My MyDomainName.conf

    ##
    # You should look at the following URL's in order to grasp a solid understanding
    # of Nginx configuration files in order to fully unleash the power of Nginx.
    # https://www.nginx.com/resources/wiki/start/
    # https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
    # https://wiki.debian.org/Nginx/DirectoryStructure
    #
    # In most cases, administrators will remove this file from sites-enabled/ and
    # leave it as reference inside of sites-available where it will continue to be
    # updated by the nginx packaging team.
    #
    # This file will automatically load configuration files provided by other
    # applications, such as Drupal or Wordpress. These applications will be made
    # available underneath a path with that package name, such as /drupal8.
    #
    # Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
    ##
    
    # Default server configuration
    #
    server {
        listen 80 default_server;
        listen [::]:80 default_server;
    
        # SSL configuration
        #
        # listen 443 ssl default_server;
        # listen [::]:443 ssl default_server;
        #
        # Note: You should disable gzip for SSL traffic.
        # See: https://bugs.debian.org/773332
        #
        # Read up on ssl_ciphers to ensure a secure configuration.
        # See: https://bugs.debian.org/765782
        #
        # Self signed certs generated by the ssl-cert package
        # Don't use them in a production server!
        #
        # include snippets/snakeoil.conf;
    
        root /var/www/html;
    
        # Add index.php to the list if you are using PHP
        index index.html index.htm index.nginx-debian.html;
    
        server_name _;
    
        location / {
            # First attempt to serve request as file, then
            # as directory, then fall back to displaying a 404.
            try_files $uri $uri/ =404;
        }
    
        # pass PHP scripts to FastCGI server
        #
        #location ~ \.php$ {
        #   include snippets/fastcgi-php.conf;
        #
        #   # With php-fpm (or other unix sockets):
        #   fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        #   # With php-cgi (or other tcp sockets):
        #   fastcgi_pass 127.0.0.1:9000;
        #}
    
        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #   deny all;
        #}
    }
    
    
    # Virtual Host configuration for example.com
    #
    # You can move that to a different file under sites-available/ and symlink that
    # to sites-enabled/ to enable it.
    #
    #server {
    #   listen 80;
    #   listen [::]:80;
    #
    #   server_name example.com;
    #
    #   root /var/www/example.com;
    #   index index.html;
    #
    #   location / {
    #       try_files $uri $uri/ =404;
    #   }
    #}
    
    edited by MattIPv4
  • I don’t know why FileZilla shows this file in a type folder but I can download this file folder and open it like file.conf .

  • Hi, I miss understood about this issue. The location of the index not change,I tried to change root /var/www/html; in /etc/nginx/sites-enabled/YourDomain.conf to something like root /var/www/sadasgfdsgs; or root /var/wwasd/dsa;, and this gonna be error but if I change it like root /var/www/; or root /var/www/html/MyPHPFolderName; it work! So this not about location but I don’t know why when I open this site by domain name or IP address, it always links to Welcome to nginx! page. Help me, please.

  • Hi, I fixed it. I never use Nginx so I just stop Nginx and restart apache.