You are not logged in.

#1 2014-11-22 23:39:57

Brother Root
Member
Registered: 2014-11-09
Posts: 43

[SOLVED] nginx development environment setup

For the first time ever I have installed nginx and hoped that having quite a few tutorials available right away will be enough, but it it is not. sad

So I've installed nginx, PHP (including php-fpm) and MySQL (mariadb), started all of those parts as services and everything's running (I can access the nginx index page, PHP "info" page works, MySQL is accessible) well, BUT - how do I configure it so that I could create any number of sub-directories under /srv/http and make index.php as the default file for each directory?

Here's the config file I am using at the moment:

#user html;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       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  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   /usr/share/nginx/html;
            index  index.html index.htm;
        }

		location ~ \.php$ {
			fastcgi_pass	unix:/var/run/php-fpm/php-fpm.sock;
			fastcgi_index	index.php;
			root			/srv/http;
			include			fastcgi.conf;
		}

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/share/nginx/html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }

    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

Note: I've spent ~2-3 hours searching for an answer with the help of master-Google, but found nothing or simply didn't get it.

Last edited by Brother Root (2014-11-23 16:14:48)

Offline

#2 2014-11-23 03:22:06

ackt1c
Banned
From: Visalia, California
Registered: 2012-10-10
Posts: 241

Re: [SOLVED] nginx development environment setup

Etc

Last edited by ackt1c (2022-11-05 13:38:12)

Offline

#3 2014-11-23 16:14:32

Brother Root
Member
Registered: 2014-11-09
Posts: 43

Re: [SOLVED] nginx development environment setup

I ended up removing the default nginx configuration file and writing it from scratch by copying "Catch All" server block example found at http://wiki.nginx.org/ServerBlockExampl … rver_Block. Exactly what I needed! Now every subdirectory of /srv/http runs index.php by default and I do not need to change anyhting in the configuration if I want to add a new directory or remove any of the directories that I have there.

Last edited by Brother Root (2014-11-23 16:15:29)

Offline

Board footer

Powered by FluxBB