Vesta Control Panel - Forum

Community Forum

Skip to content

Advanced search
  • Quick links
    • Main site
    • Github repo
    • Google Search
  • FAQ
  • Login
  • Register
  • Board index Main Section Web Server
  • Search

Adding Code To Nginx File

Questions regarding the Web Server
Apache + Nginx, Nginx + PHP5-FPM
Locked
  • Print view
Advanced search
6 posts • Page 1 of 1
msk19994
Posts: 23
Joined: Thu Jun 05, 2014 5:55 am

Adding Code To Nginx File

Post by msk19994 » Wed Jul 20, 2016 1:04 pm

Hey guys my script required a code to be added to nginx files as i am running fcgid
Note : I have replaced mywebsite name with mywebsite.com

Code: Select all

location /files {
    root /home/hosting/web/mywebsite.com/public_html;
    post_action @afterdownload;
    internal;
}

location @afterdownload {
    proxy_pass http://hostingrill.co/plugins/rewards/site/_log_download.php?request_uri=$request_uri&remote_addr=$remote_addr&body_bytes_sent=$body_bytes_sent&status=$request_completion&content_length=$content_length&http_user_agent=$http_user_agent&http_referer=$http_referer&args=$args;
    internal;
}
It said to add the code to the nginx.conf
but when i try to add it to
/home/hosting/conf/web/nginx.conf
and restart nginx it says
nginx: [emerg] "location" directive is not allowed here in /etc/nginx/conf.d/158.69.5.207.conf:10
nginx: configuration file /etc/nginx/nginx.conf test failed
and also i tried adding it to /etc/nginx/conf.d/myip.conf (Myip is the my ipaddress even though the code shouldnt be added there )
Still the same error
so please tell me what to do so that the code works in /home/hosting/conf/web/nginx.conf
Top

skurudo
VestaCP Team
Posts: 8099
Joined: Fri Dec 26, 2014 2:23 pm
Contact:
Contact skurudo
Website Facebook Google+ Skype
Twitter

Re: Adding Code To Nginx File

Post by skurudo » Wed Jul 20, 2016 1:11 pm

When you add code to /home/admin/conf/web/nginx.conf which error do you get?
Add your code right and try command

Code: Select all

nginx -t

Show us error and full config text.
Top

msk19994
Posts: 23
Joined: Thu Jun 05, 2014 5:55 am

Re: Adding Code To Nginx File

Post by msk19994 » Wed Jul 20, 2016 4:42 pm

The Error

Code: Select all

[root@picu ~]# nginx -t
nginx: [emerg] "location" directive is not allowed here in /home/hosting/conf/web/nginx.conf:33
nginx: configuration file /etc/nginx/nginx.conf test failed
Full file

Code: Select all

server {
    listen      158.69.5.207:80;
    server_name hostingrill.co www.hostingrill.co hostingrill-co.picu.pk;
    error_log  /var/log/httpd/domains/hostingrill.co.error.log error;

    location / {
        proxy_pass      http://158.69.5.207:8080;
        location ~* ^.+\.(jpeg|jpg|png|gif|bmp|ico|svg|tif|tiff|css|js|htm|html|ttf|otf|webp|woff|txt|csv|rtf|doc|docx|xls|xlsx|ppt|pptx|odf|odp|ods|odt|pdf|psd|ai|eot|eps|ps|zip|tar|tgz|gz|rar|bz2|7z|aac|m4a|mp3|mp4|ogg|wav|wma|3gp|avi|flv|m4v|mkv|mov|mpeg|mpg|wmv|exe|iso|dmg|swf)$ {
            root           /home/hosting/web/hostingrill.co/public_html;
            access_log     /var/log/httpd/domains/hostingrill.co.log combined;
            access_log     /var/log/httpd/domains/hostingrill.co.bytes bytes;
            expires        max;
            try_files      $uri @fallback;
        }
    }

    location /error/ {
        alias   /home/hosting/web/hostingrill.co/document_errors/;
    }

    location @fallback {
        proxy_pass      http://158.69.5.207:8080;
    }

    location ~ /\.ht    {return 404;}
    location ~ /\.svn/  {return 404;}
    location ~ /\.git/  {return 404;}
    location ~ /\.hg/   {return 404;}
    location ~ /\.bzr/  {return 404;}

    include /home/hosting/conf/web/nginx.hostingrill.co.conf*;
}
location /files {
    root /home/hosting/web/mywebsite.com/public_html;
    post_action @afterdownload;
    internal;
}

location @afterdownload {
    proxy_pass http://hostingrill.co/plugins/rewards/site/_log_download.php?request_uri=$request_uri&remote_addr=$remote_addr&body_bytes_sent=$body_bytes_sent&status=$request_completion&content_length=$content_length&http_user_agent=$http_user_agent&http_referer=$http_referer&args=$args;
    internal;
}
Top

skurudo
VestaCP Team
Posts: 8099
Joined: Fri Dec 26, 2014 2:23 pm
Contact:
Contact skurudo
Website Facebook Google+ Skype
Twitter

Re: Adding Code To Nginx File

Post by skurudo » Thu Jul 21, 2016 7:14 am

You add your config part too low and get error, check this:

Code: Select all

server {
    listen      158.69.5.207:80;
    server_name hostingrill.co www.hostingrill.co hostingrill-co.picu.pk;
    error_log  /var/log/httpd/domains/hostingrill.co.error.log error;

    location / {
        proxy_pass      http://158.69.5.207:8080;
        location ~* ^.+\.(jpeg|jpg|png|gif|bmp|ico|svg|tif|tiff|css|js|htm|html|ttf|otf|webp|woff|txt|csv|rtf|doc|docx|xls|xlsx|ppt|pptx|odf|odp|ods|odt|pdf|psd|ai|eot|eps|ps|zip|tar|tgz|gz|rar|bz2|7z|aac|m4a|mp3|mp4|ogg|wav|wma|3gp|avi|flv|m4v|mkv|mov|mpeg|mpg|wmv|exe|iso|dmg|swf)$ {
            root           /home/hosting/web/hostingrill.co/public_html;
            access_log     /var/log/httpd/domains/hostingrill.co.log combined;
            access_log     /var/log/httpd/domains/hostingrill.co.bytes bytes;
            expires        max;
            try_files      $uri @fallback;
        }
    }

location /files {
    root /home/hosting/web/mywebsite.com/public_html;
    post_action @afterdownload;
    internal;
}

location @afterdownload {
    proxy_pass http://hostingrill.co/plugins/rewards/site/_log_download.php?request_uri=$request_uri&remote_addr=$remote_addr&body_bytes_sent=$body_bytes_sent&status=$request_completion&content_length=$content_length&http_user_agent=$http_user_agent&http_referer=$http_referer&args=$args;
    internal;
}

    location /error/ {
        alias   /home/hosting/web/hostingrill.co/document_errors/;
    }

    location @fallback {
        proxy_pass      http://158.69.5.207:8080;
    }

    location ~ /\.ht    {return 404;}
    location ~ /\.svn/  {return 404;}
    location ~ /\.git/  {return 404;}
    location ~ /\.hg/   {return 404;}
    location ~ /\.bzr/  {return 404;}

    include /home/hosting/conf/web/nginx.hostingrill.co.conf*;
}
Top

msk19994
Posts: 23
Joined: Thu Jun 05, 2014 5:55 am

Re: Adding Code To Nginx File

Post by msk19994 » Thu Jul 21, 2016 10:28 am

wow thanks mate works good :)
Top

skurudo
VestaCP Team
Posts: 8099
Joined: Fri Dec 26, 2014 2:23 pm
Contact:
Contact skurudo
Website Facebook Google+ Skype
Twitter

Re: Adding Code To Nginx File

Post by skurudo » Fri Jul 22, 2016 1:45 pm

You're welcome ;-)
Top


Locked
  • Print view

6 posts • Page 1 of 1

Return to “Web Server”



  • Board index
  • All times are UTC
  • Delete all board cookies
  • The team
Powered by phpBB® Forum Software © phpBB Limited
*Original Author: Brad Veryard
*Updated to 3.2 by MannixMD
 

 

Login  •  Register

I forgot my password