Welcome! Log In Create A New Profile

Advanced

Nginx - invalid variable + directive is not allowed here

Posted by foto 
Nginx - invalid variable + directive is not allowed here
July 10, 2016 11:48AM
I have problem with Nginx configuration ?
My first VPS Debian8 64bit, Nginx 1.10(from dotdeb).

I saw only easy short configuration in man.

testing:

Main configuration
file: /etc/nginx/nginx.conf


sudo nginx -t
nginx: [emerg] invalid variable name in /etc/nginx/nginx.conf:54
nginx: configuration file /etc/nginx/nginx.conf test failed

54 last "}"

user www-data;
worker_processes auto;
pid /run/nginx.pid;
#include /etc/nginx/modules-enabled/*.conf;
# include /etc/nginx/conf.d/*.conf;
#include /etc/nginx/sites-enabled/*;
#include /etc/nginx/sites-available/*;



events {
worker_connections 768;
# multi_accept on;
}

http {

sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
gzip on;
gzip_disable "msie6";

server {

server_name IP_VPS mysite.com www.mysite.com;

listen 80 default_server;
listen [::]:80 default_server;

root /var/www/html;

index index.php index.html index.htm index.nginx-debian.html;


location / {
root /var/www/html;
try_files $uri $uri/ =404;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_nam$;
include fastcgi_params;

}
}
}




"site configuration" for the piwigo gallery

file:
/etc/nginx/sites-available/piwigo

After activation include /etc/nginx/sites-available/*;

sudo nginx -t
nginx: [emerg] "server" directive is not allowed here in /etc/nginx/sites-available/piwigo:1
nginx: configuration file /etc/nginx/nginx.conf test failed

If i remove server the location is directive is not allowed here



server {
location ~ /\.ht {
deny all;
}

location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}

# Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).
location ~ /\. {
deny all;
access_log off;
log_not_found off;
}

# piwigo distribution files
location ~ ^/(README|doc)$ {
deny all;
}

# prevent direct acces to uploaded images, derivates and logs
location ~ ^/(_data/(logs)/ {
deny all;
}

location / {
index index.php;
try_files $uri $uri/ @rewrite;
}

location / {
rewrite ^/picture((/|$).*)$ /picture.php$1 last;
rewrite ^/index((/|$).*)$ /index.php$1 last;
rewrite ^/i((/|$).*)$ /i.php$1 last;
}



location ~ ^(?<script_name>.+?\.php)(?<path_info>/.*)?$ {
try_files $script_name = 404;

}
}




#piwigo
client_max_body_size 50m;
client_body_buffer_size 25m;

set $check_referal "";


I tried to put everything in one file /etc/nginx/nginx.conf but it did not work.


Thank you for your attention.
Attachments:
open | download - nginx.conf.txt (1.1 KB)
open | download - piwigo.txt (1016 bytes)
Re: Nginx - invalid variable + directive is not allowed here
July 10, 2016 01:44PM
Some corrections server / locations but the "error nginx: [emerg] invalid variable name in"

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

#include /etc/nginx/modules-enabled/*.conf;
# include /etc/nginx/conf.d/*.conf;
#include /etc/nginx/sites-enabled/*;



events {
worker_connections 512;
# multi_accept on;
}

http {
#include /etc/nginx/sites-available/*;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
gzip on;
gzip_proxied any;
gzip_types text/plain /html text/css application/x-javascript;
gzip_disable "msie6";

server {

listen 80;
server_name IP_VPS mysite.com www.mysite.com;


location / {
root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;
try_files $uri $uri/ =404;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_nam$;
include fastcgi_params;
}
}
}
Re: Nginx - invalid variable + directive is not allowed here
July 10, 2016 03:29PM
Look at this line
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_nam$;

Which would also be in the logfiles.

---
nginx for Windows http://nginx-win.ecsds.eu/
Re: Nginx - invalid variable + directive is not allowed here
July 10, 2016 05:44PM
Thank you for this. I went back to a single file from http://piwigo.org/forum/viewtopic.php?pid=163083 and I added fastcgi_params.

sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
sudo service nginx restart

I see nginx worker in htop. (php-fpm7.0 is ok)

Website is only showing "error".
404 Not Found
nginx/1.10.1


user www-data;
worker_processes 1;
error_log /var/log/nginx/error.log info;
pid /var/run/nginx.pid;

events {
worker_connections 512;
}

http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

access_log /var/log/nginx/access.log combined;
error_log /var/log/nginx/error.log;
sendfile on;
keepalive_timeout 65;
tcp_nodelay on;
tcp_nopush on;
types_hash_max_size 2048;

gzip on;
gzip_proxied any;
gzip_types text/plain /html text/css application/x-javascript;
gzip_disable "msie6";

uninitialized_variable_warn on;



server {
listen 80;
server_name localhost mysite.com www.mysite.com;
client_max_body_size 50m;
client_body_buffer_size 25m;


location / {
root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;
try_files $uri $uri/ @rewrite;
}

location @rewrite {
rewrite ^/picture((/|$).*)$ /picture.php$1 last;
rewrite ^/index((/|$).*)$ /index.php$1 last;
rewrite ^/i((/|$).*)$ /i.php$1 last;
}

location ~ ^(?<script_name>.+?\.php)(?<path_info>/.*)?$ {
try_files $script_name = 404;
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_param PATH_INFO $path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location ~ ^/favicon.ico$ {
log_not_found off;
access_log off;
expires max;
}

location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}

# Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).
location ~ /\. {
deny all;
access_log off;
log_not_found off;
}

# piwigo distribution files
location ~ ^/(README|doc)$ {
deny all;
}
# prevent direct acces to logs
location ~ ^/(_data/(|logs))/ {
deny all;
}


#error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# root /var/www/nginx-default;

}
}



Edited 1 time(s). Last edit at 07/10/2016 05:54PM by foto.
Re: Nginx - invalid variable + directive is not allowed here
July 11, 2016 12:58AM
Look in the nginx logfiles, or enable debug logging to see which location block is doing what.

---
nginx for Windows http://nginx-win.ecsds.eu/
Re: Nginx - invalid variable + directive is not allowed here
July 11, 2016 06:52PM
sudo journalctl -xn

-- Logs begin at sob 2016-07-09 21:28:50 CEST, end at pon 2016-07-11 23:41:50 CEST. --
lip 11 23:40:13 Foto nginx[4680]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
lip 11 23:40:13 Foto nginx[4680]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
lip 11 23:40:14 Foto nginx[4680]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

sudo systemctl status nginx.service
(...)
Process: 4423 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid (code=exited, status=1/FAILURE)
(...)

I fix "listen 80" (and pid?) /http://stackoverflow.com/questions/14972792/nginx-nginx-emerg-bind-to-80-failed-98-address-already-in-use

by:
listen 80;
listen [::]:80 ipv6only=on default_server;


sudo systemctl status nginx

nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled)
Active: active (running) since wto 2016-07-12 00:01:29 CEST; 48min ago
Docs: man:nginx(8)
Process: 4888 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid (code=exited, status=0/SUCCESS)
Process: 4894 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Process: 4893 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Main PID: 4897 (nginx)
CGroup: /system.slice/nginx.service
├─4897 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
└─4898 nginx: worker process



Error log (full)
http://pastebin.com/g0ZMqd4m

last lines
2016/07/12 00:02:33 [error] 4898#4898: *1 open() "/usr/share/nginx/html404" failed (2: No such file or directory), client: 31.183.115.252, server: localhost, request: "GET /info.php HTTP/1.1", host: "mysite.com"
2016/07/12 00:02:39 [error] 4898#4898: *1 open() "/usr/share/nginx/html404" failed (2: No such file or directory), client: 31.183.115.252, server: localhost, request: "GET / HTTP/1.1", host: "mysite.com"
2016/07/12 00:02:54 [error] 4898#4898: *3 open() "/usr/share/nginx/html404" failed (2: No such file or directory), client: 31.183.115.252, server: localhost, request: "GET / HTTP/1.1", host: "www.mysite.com"

Yes I don't have /usr/share/nginx/html404
Google
https://www.queryxchange.com/q/1_767809/redirect-to-home-myuser-public-html/


But ngnix can't see

location / {
root /var/www/html; ?

*i try debug tomorrrow



Edited 1 time(s). Last edit at 07/11/2016 06:58PM by foto.
Re: Nginx - invalid variable + directive is not allowed here
July 12, 2016 05:12PM
Debug

server {
#other config
error_log /var/logs/nginx/mysitecom.log debug;
#other config
}


full http://pastebin.com/AC5itJxf

Refresh main site.

Ngnix site trying to use "/" "/var/www/html/" and forwarding(?) to /usr/share/nginx and error 404.

(...)
2016/07/12 22:04:31 [debug] 16736#16736: *8 trying to use file: "/" "/var/www/html/"
2016/07/12 22:04:31 [debug] 16736#16736: *8 http script var: "/"
2016/07/12 22:04:31 [debug] 16736#16736: *8 trying to use dir: "/" "/var/www/html/"
2016/07/12 22:04:31 [debug] 16736#16736: *8 try file uri: "/"
2016/07/12 22:04:31 [debug] 16736#16736: *8 content phase: 14
2016/07/12 22:04:31 [debug] 16736#16736: *8 content phase: 15
2016/07/12 22:04:31 [debug] 16736#16736: *8 open index "/var/www/html/index.php"
2016/07/12 22:04:31 [debug] 16736#16736: *8 internal redirect: "/index.php?"
2016/07/12 22:04:31 [debug] 16736#16736: *8 rewrite phase: 2
2016/07/12 22:04:31 [debug] 16736#16736: *8 test location: "/"
2016/07/12 22:04:31 [debug] 16736#16736: *8 test location: "robots.txt"
(...)
2016/07/12 22:04:31 [debug] 16736#16736: *8 http script var: "/index.php"
2016/07/12 22:04:31 [debug] 16736#16736: *8 trying to use file: "/index.php" "/usr/share/nginx/html/index.php"
2016/07/12 22:04:31 [debug] 16736#16736: *8 trying to use file: "=" "/usr/share/nginx/html="
2016/07/12 22:04:31 [debug] 16736#16736: *8 trying to use file: "404" "/usr/share/nginx/html404"
2016/07/12 22:04:31 [debug] 16736#16736: *8 internal redirect: "404?"
(...)
2016/07/12 22:04:31 [debug] 16736#16736: *8 http filename: "/usr/share/nginx/html404"
2016/07/12 22:04:31 [debug] 16736#16736: *8 add cleanup: 00000000008AEB48
2016/07/12 22:04:31 [error] 16736#16736: *8 open() "/usr/share/nginx/html404" failed (2: No such file or directory), client: 31.183.115.252, server: localhost, request: "GET / HTTP/1.1", host: "mywebsite.com"
2016/07/12 22:04:31 [debug] 16736#16736: *8 http finalize request: 404, "404?" a:1, c:3
2016/07/12 22:04:31 [debug] 16736#16736: *8 http special response: 404, "404?"
2016/07/12 22:04:31 [debug] 16736#16736: *8 http set discard body
2016/07/12 22:04:31 [debug] 16736#16736: *8 HTTP/1.1 404 Not Found
Server: nginx/1.10.1
Date: Tue, 12 Jul 2016 20:04:31 GMT
Re: Nginx - invalid variable + directive is not allowed here
July 12, 2016 05:20PM
2016/07/12 22:04:31 [debug] 16736#16736: *8 trying to use file: "/index.php" "/usr/share/nginx/html/index.php"
(...)
2016/07/12 22:04:31 [error] 16736#16736: *8 open() "/usr/share/nginx/html404" failed

You will have to investigate if those files are there, maybe a rights issue.

---
nginx for Windows http://nginx-win.ecsds.eu/
Re: Nginx - invalid variable + directive is not allowed here
July 15, 2016 07:33PM
Permission for file ? ( sudo chmod -R 777 /var/www/ risk but for test )
Site is working ok under apache2 + libapache2-mod-php7.0 php 7,

Back to Nginx
I check usr/share/nginx/html .......

What I see ?
index.html, i copy here info.php too.

So I tried mysite/index.html
Welcome to nginx!

mysite/index.html
Information about PHP

I was searching information about root and www directory <-> usr , and

root /var/www/html;

cannot be in "location". Move under server fix all problems. :)



itpp2012
Thanks for all your advice.

Nginx/php fpm is more effective than apache2 in "viewing/explore" a large number of thumbnails (Plug Piwigo: "RV Thumbnail Scroller"Asynchronously loads thumbnails using ajax on index page as you scroll down to the bottom of the page.
Aka infinite scroll").
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 124
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready