0

Hello I am setting up php with nginix and I need to add some code to the

/etc/nginx/nginx.conf file. 

My nginx.conf file currently looks like this

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


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

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    gzip  on;

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

I am getting this error when I try to add the lines below

location directive is not allowed here in /etc/nginx/nginx.conf

lines I am trying to add

   location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /usr/share/nginx/html$fastcgi_script_name;
            include        fastcgi_params;
        }

The complete script after adding the lines looks like this

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


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

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    gzip  on;

    include /etc/nginx/conf.d/*.conf;
}
location ~ \.php$ {
                root           html;
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  /usr/share/nginx/html$fastcgi_script_name;
                include        fastcgi_params;
            }

P.S the tutorial I am following to install php in nginx can be found at http://www.cyberciti.biz/faq/rhel-fedora-install-configure-nginx-php5/

Please help me setup

Rick Roy
  • 237
  • 1
  • 5
  • 15
  • You need to show us where within your nginx.conf file you are inserting the location directive. – user9517 Dec 23 '13 at 06:47
  • @lain edited the question to show how i was setting up the `nginx.conf` file, searching around the forum i came to understand that the location directive can be used only under the server block so i modified my `default.conf` file inside the `/etc/nginx/conf.d` folder and now it seems to work fine. Wonder why the tutorial is asking to modify the wrong file – Rick Roy Dec 23 '13 at 06:52
  • It's not, you're just misunderstanding it. – user9517 Dec 23 '13 at 09:29

1 Answers1

1

Please check nginx reference:

Location can only be added inside a server { } block or another location { } block

Context:    server location
ray
  • 471
  • 3
  • 3