Skip to content

Instantly share code, notes, and snippets.

@aa6my
Last active August 11, 2017 02:22
Show Gist options
  • Save aa6my/5cf32372fdaf7b1ef02c1cb04cae93eb to your computer and use it in GitHub Desktop.
Save aa6my/5cf32372fdaf7b1ef02c1cb04cae93eb to your computer and use it in GitHub Desktop.

Tutorial Nginx aa6my

sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get -y install php5.6 php5.6-mcrypt php5.6-mbstring php5.6-curl php5.6-cli php5.6-mysql php5.6-gd php5.6-intl php5.6-xsl php5.6-zip
curl -sS https://getcomposer.org/installer -o composer-setup.php
php -r "if (hash_file('SHA384', 'composer-setup.php') === '669656bab3166a7aff8a7506b8cb2d1c292f042046c5a994c43155c0be6190fa0355160742ab2e1c88d40d5be660b410') { echo 'Installer verified'; } else { echo 'Installer corrupt';
unlink('composer-setup.php'); } echo PHP_EOL;"
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
sudo add-apt-repository ppa:certbot/certbot
sudo apt-get update
sudo apt-get install nginx
sudo apt-get install python-certbot-nginx
depends how many domain you want start with -d
sudo certbot certonly -a webroot --webroot-path=/var/www/html -d yourdomain.com -d api.yourdomain.com
sudo crontab -e #chose nano
paste this
15 3 * * * /usr/bin/certbot renew --quiet
sudo nano /etc/nginx/sites-available/yourdomain.com
write your config base on domain
server {
        listen 80;
        listen [::]:80;
        server_name yourdomain.com;
        return 301 https://$host$request_uri;
}

server {
        listen 443 ssl;
        ssl_certificate /etc/letsencrypt/live/yourdomain.com/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/yourdomain.com/privkey.pem;
        root /home/ubuntu/Code/yourdomain.com/public;
        # Add index.php to the list if you are using PHP
        index index.php index.html index.htm index.nginx-debian.html;
        server_name yourdomain.com;

        location / {
                try_files $uri $uri/ /index.php?$query_string;
        }

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php5.6-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

        fastcgi_intercept_errors off;
        fastcgi_buffer_size 16k;
        fastcgi_buffers 4 16k;
        fastcgi_connect_timeout 300;
        fastcgi_send_timeout 300;
        fastcgi_read_timeout 300;
    }

}
sudo ln -s /etc/nginx/sites-available/yourdomain.com /etc/nginx/sites-enabled/yourdomain.com
sudo service nginx restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment