Skip to content

Instantly share code, notes, and snippets.

Created February 27, 2013 14:47
Show Gist options
  • Save anonymous/5048406 to your computer and use it in GitHub Desktop.
Save anonymous/5048406 to your computer and use it in GitHub Desktop.
Small tutorial to install Nginx.
# https://www.digitalocean.com/community/articles/how-to-install-linux-nginx-mysql-php-lemp-stack-on-ubuntu-12-04
sudo apt-get update
sudo apt-get install mysql-server
sudo apt-get install nginx
sudo service nginx start
sudo apt-get install php5-fpm php5-suhosin php-apc php5-gd php5-imagick php5-curl php5-mysql
sudo vim /etc/php5/fpm/php.ini
cgi.fix_pathinfo=0
sudo service php5-fpm restart
cd /etc/nginx/sites-available/
sudo cp default domain.com
sudo vim domain.com
[...]
server {
listen 80; ## listen for ipv4; this line is default and implied
#listen [::]:80 default_server ipv6only=on; ## listen for ipv6
root /vagrant/www/clickbrasilia.com.br;
index index.php index.html index.htm;
# Make site accessible from http://localhost/
server_name clickbrasilia.com.br;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
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;
allow ::1;
deny all;
}
location ~* (jpg|jpeg|gif|png|js|css) {
expires 0;
access_log off;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires -1;
log_not_found off;
}
client_max_body_size 20M;
# Only for nginx-naxsi used with nginx-naxsi-ui : process denied requests
#location /RequestDenied {
# proxy_pass http://127.0.0.1:8080;
#}
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;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
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;
#}
}
[...]
sudo nano /usr/share/nginx/www/info.php
<?php phpinfo(); ?>
sudo service nginx restart
#
ln -s /etc/nginx/sites-available/myapp /etc/nginx/sites-enabled/myapp
# test
sudo nginx -t
# reload config
sudo nginx -s reload
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment