virtual host nginx ubuntu
install nginx
sudo apt install nginx
run servicenya
sudo systemctl stop nginx.service sudo systemctl start nginx.service sudo systemctl enable nginx.service
install php
sudo apt install php-fpm php-common php-mbstring php-xmlrpc php-soap php-gd php-xml php-mysql php-cli php-mcrypt php-zip
Configure Nginx
bikin file laravel untuk config di
/etc/nginx/sites-available
sudo nano /etc/nginx/sites-available/laravel
server {
listen 80;
listen [::]:80;
server_name laravel.dev;
root /home/sulaeman/php/askrindo/bitbucket/api/public;
index index.php index.html index.htm;
# set expiration of assets to MAX for caching
location ~* \.(ico|css|js|gif|jpe?g|png)(\?[0-9]+)?$ {
expires max;
log_not_found off;
}
location ~ \.php$ {
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
}
}
enable rewrite module
config by port
server {
listen 8002;
listen [::]:8002;
server_name api.ubuntu.com;
root /var/www/html/finaku-api/public;
index index.html index.htm index.php;
location / {
try_files $uri $uri /index.php?$query_string;
}
# set expiration of assets to MAX for caching
location ~* \.(ico|css|js|gif|jpe?g|png)(\?[0-9]+)?$ {
expires max;
log_not_found off;
}
location ~ \.php$ {
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
}
}
server{
listen 80;
listen [::]:80;
server_name relpos.namealus.id;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
proxy_buffers 16 64k;
proxy_buffer_size 128k;
location / {
proxy_pass http://127.0.0.1:8003;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto http;
}
}
sudo ln -s /etc/nginx/sites-available/laravel /etc/nginx/sites-enabled/
sudo systemctl restart nginx.service
Edit file host (jika dijalankan di local dev)
sudo nano /etc/hosts
tambahkan
127.0.1.1 laravel.dev
restart nginx
sudo systemctl restart nginx.service
run
http://laravel.dev
artikel ini bersumber dari dengan tambahan setting
https://www.websitevidya.com/fix-403-forbidden-error-nginx-ubuntu/
BalasHapustambahan
BalasHapussudo chmod -R 777 public
sudo chmod -R 777 storage