nginx not letting me change the web root

Posted on

nginx not letting me change the web root – Managing your servers can streamline the performance of your team by allowing them to complete complex tasks faster. Plus, it can enable them to detect problems early on before they get out of hand and compromise your business. As a result, the risk of experiencing operational setbacks is drastically lower.

But the only way to make the most of your server management is to perform it correctly. And to help you do so, this article will share nine tips on improving your server management and fix some problem about linux, nginx, web-server, tomcat, docker.

Even though I change the root directive to point to /var/www/html, nginx is attempting to load files out of /var/www as my root directory.

I have restarted nginx and received “OK” after changing default.conf.

Am I doing something wrong? Worth nothing, this nginx server is running inside a docker container.

==================================

/etc/nginx/nginx.conf

user www-data;
worker_processes 4;
pid /run/nginx.pid;

events {
        worker_connections 768;
        # multi_accept on;
}

http {

        ##
        # Basic Settings
        ##

        sendfile off;
        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;

        ##
        # 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/x-javascript text/xml application/xml application/xml+rss text/javascript;

        ##
        # nginx-naxsi config
        ##
        # Uncomment it if you installed nginx-naxsi
        ##

        #include /etc/nginx/naxsi_core.rules;

        ##
        # nginx-passenger config
        ##
        # Uncomment it if you installed nginx-passenger
        ##

        #passenger_root /usr;
        #passenger_ruby /usr/bin/ruby;

        ##
        # Virtual Host Configs
        ##

        include /etc/nginx/conf.d/*.conf;
}

/etc/nginx/conf.d/default.conf

server {
    listen 80 default_server;
    server_name _;
    index  index.cfm index.html index.htm;
    root   /var/www/html;
    server_name_in_redirect off;

    set $path_info $request_uri;

    try_files $uri /index.cfm?$args;

    location ~* .(cfm|cfc|cfr)$ {
        proxy_pass http://127.0.0.1:8888;
        proxy_redirect off;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-Server $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header XAJP-PATH-INFO $path_info;
        proxy_connect_timeout 600;
        proxy_send_timeout 600;
        proxy_read_timeout 600;
        send_timeout 600;
    }

}

nginx root not correct

Solution :

You have configured nginx to use this root path for your website. This applies to static resources served by nginx.

However, your application server doesn’t use nginx root option, since it is independent from nginx.

You need to fix your application server configuration.

Leave a Reply

Your email address will not be published. Required fields are marked *