Problem with configuring nginx

0

Save personal, I'm having trouble with this setting:

local do arquivo: /etc/nginx/conf.d/virtual.conf

#
# A virtual host using mix of IP-, name-, and port-based configuration
#

server {
    listen 80; # porta
    server_name sitex.com.br www.sitex.com.br; # site

    access_log off; # logs de acesso
    error_log /var/log/nginx/sitex.com.br.error.log; # local dos logs

    root /var/www/vhosts/sitex.com.br/public; # local da pasta

    index .index.html index.php; # index da pagina

    location / {
            try_files $uri $uri/ /index.php?q=$uri&$args;
    }

    location ~* \.(?:ico|css|js|gif|jpe?g|png)${
            expires max;
            add_header Pragma public;
            add_header Cache-Control "public, must-revalidate, proxy-revalidate";
    }

    location ~ \.(php|phtml)${
            include /etc/nginx/fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $request_filename;
            fastcgi_pass 127.0.0.1:9000;
    }

    location ~ /\. { deny all; }

}

With this configuration file you are returning an error while restarting nginx:

/etc/init.d/nginx restart
nginx: [emerg] directive "location" has no opening "{" in /etc/ngin/conf.d/virtual.conf:21
nginx: configuration file /etc/nginx/nginx.conf test failed

This is the first time I use it, so I'm not sure if this code is correct.

    
asked by anonymous 02.09.2015 / 15:48

1 answer

0

I was able to solve the problem thanks to the help of the instructor: the error was only where:

  

location ~ *. (?: ico | css | js | gif | jpe? g | png) $ {

and

  

location ~. (php | php) $ {

put a space between $ and {:

  

location ~ *. (?: ico | css | js | gif | jpe? g | png) $ {

     

location ~. (php | php) $ {

local do arquivo: /etc/nginx/conf.d/virtual.conf

#
# A virtual host using mix of IP-, name-, and port-based configuration
#

server {
listen 80; # porta
server_name sitex.com.br www.sitex.com.br; # site

access_log off; # logs de acesso
error_log /var/log/nginx/sitex.com.br.error.log; # local dos logs

root /var/www/vhosts/sitex.com.br/public; # local da pasta

index .index.html index.php; # index da pagina

location / {
        try_files $uri $uri/ /index.php?q=$uri&$args;
}

location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {
        expires max;
        add_header Pragma public;
        add_header Cache-Control "public, must-revalidate, proxy-revalidate";
}

location ~ \.(php|phtml)$ {
        include /etc/nginx/fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $request_filename;
        fastcgi_pass 127.0.0.1:9000;
}

location ~ /\. { deny all; }

}

Fixed. This is the tip for anyone going through the same problem. Thanks.

    
09.09.2015 / 15:39