Stranica: 1/1.

nginx na xubuntu 12.04

Postano: 24 vel 2013, 14:59
Postao/la hightech
Instalacija na Xubuntu 12.04 se razlikuje od instalacije na Ubuntu 10.04 i Debianu(stable), zapravo razlikuje se iz razloga default verzije nginx-a. U ovom slučaju default verzija nginx-a je 1.1.9 - nginx version: nginx/1.1.19, dok je na Debian stable 0.7.67 osim u backport riznicama, gde je 1.2.1 ...
Prvo par paketa:

Kod: Označi sve

sudo aptitude install php5-cgi php5-cli php5-common php5-mhash php5-curl php5-gd php5-json php5-mcrypt php5-sqlite php5-mysql php5-dev php5-tidy php5-xmlrpc php5-memcache php5-pspell php5-xsl
Pa spawn-cgi:

Kod: Označi sve

sudo aptitude install spawn-fcgi
pa nginx:

Kod: Označi sve

sudo aptitude install nginx
Pa napraviti direktorijume public i logs

Kod: Označi sve

sudo mkdir -p /home/www/public
sudo mkdir /home/www/logs
Pa editovati /etc/nginx/sites-available/default i on treba izgledati ovako:

Kod: Označi sve

server {
        listen   80; ## listen for ipv4; this line is default and implied
        listen   [::]:80 default ipv6only=on; ## listen for ipv6
        root /home/www/public;
        index index.html index.htm index.php;
        # Make site accessible from http://localhost/
        server_name localhost;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to index.html
                try_files $uri $uri/ /index.html;
                # Uncomment to enable naxsi on this location
                # include /etc/nginx/naxsi.rules
         }

        location /doc/ {
                alias /usr/share/doc/;
                autoindex on;
                allow 127.0.0.1;
                deny all;
         }

        # Only for nginx-naxsi : process denied requests
        #location /RequestDenied {
                # For example, return an error code
                #return 418;
        #}
        #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/www;
        #}

        location ~ \.php$ {
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini

                # With php5-cgi alone:
                fastcgi_pass 127.0.0.1:9000;
                # With php5-fpm:
                #fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                include fastcgi_params;
        }

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

Kod: Označi sve

sudo ln -s /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default
Pa editovati fastcgi:

Kod: Označi sve

sudo nano /etc/init.d/php-fastcgi
Sadržaj:

Kod: Označi sve

#!/bin/bash
BIND=127.0.0.1:9000
USER=www-data
PHP_FCGI_CHILDREN=5 #15
PHP_FCGI_MAX_REQUESTS=1000
PHP_CGI=/usr/bin/php-cgi
PHP_CGI_NAME='basename $PHP_CGI'
PHP_CGI_ARGS="- USER=$USER PATH=/usr/bin 
PHP_FCGI_CHILDREN=$PHP_FCGI_CHILDREN PHP_FCGI_MAX_REQUESTS=$PHP_FCGI_MAX_REQUESTS  $PHP_CGI -b $BIND"
RETVAL=0
 start() {
	echo -n "Starting PHP FastCGI: "
	start-stop-daemon --quiet --start --background --chuid "$USER" --exec /usr/bin/env -- $PHP_CGI_ARGS
	RETVAL=$?
	echo "$PHP_CGI_NAME."
 }
 stop() {
	echo -n "Stopping PHP FastCGI: "
	killall -q -w -u $USER $PHP_CGI
	RETVAL=$?
	echo "$PHP_CGI_NAME."
 }
 case "$1" in

	start)
	start
		;;
	stop)
	stop
		;;
	restart)
	stop
	start
		;;
 *)
 echo "Usage: php-fastcgi {start|stop|restart}"
	exit 1
		;;
	esac
 exit $RETVAL
Izmeniti dozvole nad php-fastcgi u izvršne:

Kod: Označi sve

sudo chmod +x /etc/init.d/php-fastcgi 
Pokrenuti nginx:

Kod: Označi sve

sudo /etc/init.d/nginx start
Pokrenuti fastcgi:

Kod: Označi sve

sudo /etc/init.d/php-fastcgi start

...pa:

Kod: Označi sve

sudo update-rc.d nginx defaults

...zatim:

Kod: Označi sve

sudo update-rc.d php-fastcgi defaults
zatim napraviti index.php i ubaciti phpinfo() funkciju:

Kod: Označi sve

sudo nano /home/www/public/index.php
index.php bi trebao izgledati ovako:

Kod: Označi sve

<?php echo phpinfo(); ?> 
Pa ownership(vlasništvo) i dozvole:

Kod: Označi sve

sudo chown -R www-data:www-data /home/www/public
sudo chmod -R 755 /home/www/public 
Gotovo!!! Sada otvorite browser i kucajte:
http://localhost
web strane našeg servera se nalaze u /home/www/public/