Problem with Nginx configuration

Asked

Viewed 520 times

0

Hail personal, I’m having trouble with this setup:

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 is returning me an error while giving Restart to 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

It’s the first time I’ve used it, so I’m not sure if that code is correct.

1 answer

0


I was able to solve the problem by helping the instructor: the error was just where:

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

and

Location ~ . (php|phtml)${

put a gap between $ and {:

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

Location ~ . (php|phtml)$ {

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; }

}

Solved. This is a tip for anyone who has the same problem. Thanks.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.