Deployment Laravel 5.4 - DigitalOcean - Nginx LEMP (16.04) - nginx

i'm deployment my laravel project in digitalocean, actually i have this situation:
DNS RECORDS - GODADDY
digitalocean ip server 104.131.16.82
DNS RECORDS DIGITALOCEAN
SERVER BLOCK ENABLED
i enabled my default server block in "/etc/nginx/sites-available/default" and created link in "/etc/nginx/sites-enabled/default" like this:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /var/www/mysite-test.com/public;
index index.php index.html index.htm;
# Make site accessible from http://localhost/
server_name localhost;
return 301 $scheme://mysite-test.com$request_uri;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ /index.php?$query_string;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php7-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
i followed this tutorial to install: https://gist.github.com/naveenyagati/5deec8fc40a2faaff20c629362dddf39
Actually if i go to 104.131.16.82 download a file, i don't know why, it doesn't work well, maybe i have error in server block? or DNS records?
thank you for your help!

If you have deployed using ONE CLICK APP INSTALL in Digital Ocean you have to edit the file named "digitalocean" in "/etc/nginx/site-available" directory not the "default" file for changes to take effect. If not the default LEMP landing page would be shown there.
Command to edit the main file,in digital ocean ONE CLICK APP INSTALL
sudo nano /etc/nginx/sites-available/digitalocean
Now replace the contents of the file with the following code
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /var/www/laravel/public;
index index.php index.html index.htm;
# Make site accessible from http://localhost/
server_name <Your Domain name / Public IP Address>;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ /index.php?$query_string;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Replace the server_name part with your
server IP or domain name
Further reference could be found in the following gist that I have made
https://gist.github.com/naveenyagati/5deec8fc40a2faaff20c629362dddf39

Related

I add nginx config of domain but my domain is not going online

I want to add a domain manually with cli of centos 7 and created a config file in sites-available directory:
server {
listen 80;
server_name hustana.ir www.hustana.ir;
location / {
root /home/www/public_html;
index index.html index.htm;
try_files $uri $uri/ =404;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
In my server there is another domains that are online and works fine.
if its help I should tell that at start my server was worked by Plesk Obtisian control panel
but now I wanna add another domain to server just but it`s not working.
I changed my domain NS from domain control center.
additional description:
I guess it`s good to say that if I delete the config block of one of my older domains , domain still stay online but it displays just a blank white page.
I tried add to include this config file from another directory directly into nginx.conf:
server {
listen 80;
server_name hustana.ir;
root /home/www/public_html;
index index.php;
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
You need to enable your site as mentioned here.
Check the A-record of your domain. It must point to your server IP.

Setting up multiple domains on nginx server

I have one nginx server on ubuntu running a single application. I want let multiple domains point to this server.
Currently my /etc/nginx/sites-available/default looks like this:
(website1.com is just an example as I don't want to give out my real domain)
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/website/public;
index index.php index.html index.htm;
server_name website1.com;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME
$document_root$fastcgi_script_name;
include fastcgi_params;
}
}
This works when someone going to website1.com
Now if people coming from website2.com do i just copy the code again exactly and change the server_name?
Or is there anything else I must do?
You can just list as many domain names on your server name directive
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/website/public;
index index.php index.html index.htm;
server_name website1.com website2.com website3.com;
...
Bear in mind that you would need a dns that resolves website2.com to the same ip as website2.com also!

nginx multiple domain issue

I want to host two website on my ubuntu VPS with nginx . so i created two copy of default config :domain1.com and domain2.com
config for domain1.com:
server {
listen 80 ;
listen [::]:80 ;
root /home/sher/ftp/www/public;
server_name domain1.com www.domain1.com;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
#try_files $uri $uri/ =404;
try_files $uri $uri/ /index.php?$query_string;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
if user type in www.domain1.com in browser he would see domain1 site. but if he hit it without www he would see domain2.com .i've created symlinks from these two config files to sites-enabled .
P.S : I set listen to default_server for domain1 and it seems the issue solved but im not sure if it is the right way.

NGINX doesn't work if the domain has an accent mark

I have bought a domain with an accent mark inside: something like www.èxample.com.
My problem is that even if I configured my nginx server block (virtual host) in a correct way, it doesn't match the directory that I made.
I tried to use the same configuration with a domain without an accent mark and everything work fine.
This is my server block file inside site-availables folder:
server {
listen 80;
root /var/www/example.com;
index index.php index.html index.html;
server_name *.èxample.com;
client_max_body_size 4G;
charset utf-8;
access_log /var/www/example.com/logs/nginx-access.log;
error_log /var/www/example.com/logs/nginx-error.log;
location / {
try_files $uri $uri/ /index.html;
}
# pass the PHP scripts to FastCGI server listening on the php-fpm socket
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
How can I solve this problem?
Thanks!

Yourls Errors in WordPress

I have wordpress working well in mysite.com
but YOURLS which is installed in mysite.com/u is not working, when I click on any shortened link I get a 404 error (wordpress).
However, I get YOURLS to work by adding this to nginx.conf
location /u { try_files $uri $uri/ /u/yourls-loader.php;
But then WordPress links break.
Here is my default nginx.conf
I know the fix is to add this try_files $uri $uri/ /u/yourls-loader.php; somewhere in nginx.conf , but where to put it without breaking wordpress.?
=================== Update 1 =========================
I got this partially working. with same config, but I noticed that wordpress links that start with u doesn't work ex: http://example.com/understand-math instead it redirect to Error 403 - Forbidden
???
================ update 2 ============
ok I fixed it by just adding another slash / to location /u/ instead of location /u
YOURLs NGINX CONFIGURATION
server {
# Listen IPv4 & v6
listen 80;
listen [::]:80;
# Optional SSL stuff
listen 443 ssl;
listen [::]:443 ssl;
ssl_certificate example.com.crt;
ssl_certificate_key example.com.key;
# Server names
server_name example.com www.example.com;
# Root directory (NEEDS CONFIGURATION)
root /path/to/files;
# Rewrites
location / {
# Try files, then folders, then yourls-loader.php
# --- The most important line ---
try_files $uri $uri/ /yourls-loader.php;
# PHP engine
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock; # Can be different
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
}
GITHUB DOCUMENTATION

Resources