My local dev env is configured on nginx as is
server {
listen 80;
server_name project.local;
root /var/www/project.local/public;
charset utf-8;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
# Questi due parametri sono fondamentali
# per le app Laravel
# => https://serverfault.com/a/927619/178670
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
location ~ /\.(?!well-known).* {
deny all;
}
}
The problem is only about a folder /fonts that is inside the root, at /var/www/project.local/fonts
Note: it's not my code, I inherited it... :(
Note 2: it's an old laravel 5.4 project
Actually when the website looks for fonts/some.file I got a 404, but the file is already here.
What should I change in nginx conf to allow serving /fonts/some.file from /var/www/project.local/fonts ?
Why actually is not working?
Fixed adding
location /fonts {
root /var/www/prod.revisions;
}
Related
I have deployed a Drupal site that was developed on DigitalOcean Ubuntu onto AWS EC2 Ubuntu. So essentially the directory structure and configuration files are copied from DigitalOcean VPS. But the site on DigitalOcean is accessible while that on AWS throws a ERR_CONNECTION_REFUSED error on the browser.
I have beenn trying for several hours and haven't found any reason why the AWS site doesn't load. There are no error and access log messages in /var/log/nginx
My /etc/nginx/nginx.conf has the following line so I am sure the configuration files in /etc/nginx/sites-enabled folder are being read by Nginx.
include /etc/nginx/sites-enabled/*.*;
The /etc/nginx/sites-enabled has sym links to /etc/nginx/sites-available directory and the /etc/nginx/sites-available/domain.conf contains the following
server {
listen subdomain.domain.biz;
server_name subdomain.domain.biz;
root /home/sridhar/public_html/domain/public;
keepalive_timeout 70;
access_log /home/sridhar/public_html/domain/log/access.log;
error_log /home/sridhar/public_html/domain/log/error.log;
# Enable compression, this will help if you have for instance advagg ^ modue# by serving Gzip versions of the files.
gzip_static on;
index index.php;
#index index.php index.html index.htm;
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location ~* \.(txt|log)$ {
allow 192.168.0.0/16;
deny all;
}
location ~ \..*/.*\.php$ {
return 403;
}
# No no for private
location ~ ^/sites/.*/private/ {
return 403;
}
location ~ (^|/)\. {
return 403;
}
location / {
try_files $uri $uri/ #rewrite;
expires max;
}
location #rewrite {
rewrite ^/(.*)$ /index.php?q=$1;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
#NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors on;
#fastcgi_pass unix:/tmp/phpfpm.sock;
fastcgi_pass 127.0.0.1:9000;
}
location ~ ^/sites/.*/files/styles/ {
try_files $uri $uri/ #rewrite;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}
}
Is there any specific configuration that needs to be cariied out for AWS EC2? Or have I missed something.
Im trying to configure nginx to serve laravel and yii project on same domain. My laravel project is working fine. Yii project also working but assets folder on yii project is giving err_aborted not found 404. All js css ... files are not found
server {
server_name mydomain.com;
index index.html index.php;
charset utf-8;
set $base_root /var/www;
# App 1 (main app)
location / {
root $base_root/telemele/public;
try_files $uri $uri/ /index.php?$query_string;
error_log /var/log/nginx/telemele.notice.log notice;
error_log /var/log/nginx/telemele.error.log error;
location ~* ^/index\.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /var/www/telemele/public/index.php;
fastcgi_intercept_errors off;
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
}
}
# App 2
location ~* /mahabat {
alias $base_root/html/backend/web;
try_files $uri $uri/ /mahabat/index.php?$query_string;
error_log /var/log/nginx/mahabat.notice.log notice;
error_log /var/log/nginx/mahabat.error.log error;
location ~* ^/mahabat/index\.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /var/www/html/backend/web/index.php;
fastcgi_intercept_errors off;
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
}
location ~* \.css|\.js|\.jpg|\.jpeg|\.png|\.gif|\.swf|\.svg|\.tiff|\.pdf$ {
try_files $uri =404;
}
location ~ ^/assets/.+\.php(/|$) {
deny all;
}
}
# Files
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
# Error
access_log off;
rewrite_log on;
# Disable .htaccess access
location ~ /\.ht {
deny all;
}
}
What am i doing wrong? How to make nginx not to abort assets folder files? why it is giving not found?
There might be a missing .htacces file at the frontend/web directory. If you have the same problem, I recommend you to use this
I had three WordPress Installations /basketball /football and /kitesurfen each was defined in nginx.conf file with separate directories.
removed all configurations and installed a multisite on / path.
when I create new site with one of the previous paths e.g /basketball /football or /kitesurfen I can not access the dashboard. I get ERR_TOO_MANY_REDIRECTS and different error based on browser.
If I create a site with any other path e.g /test /volleyball or /swimming it works fine.
Need help to fix this. I am not sure if its a WordPress (PHP) error or Nginx configurations error.
Nginx Conf
if (!-e $request_filename) {
rewrite ^/([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) /$2 break;
}
location / {
root /var/www/html/multinetworks/networktheme;
index index.html index.htm index.php;
rewrite ^/([_0-9a-zA-Z-]+/)?wp-admin$ /$1wp-admin/ redirect;
rewrite ^/([_0-9a-zA-Z-]+/)?(.*\.php)$ /$2 break;
rewrite ^/([_0-9a-zA-Z-]+/)?(.*\.php)$ /$2 break;
try_files $uri $uri/ /index.php$is_args$args;
location = /favicon.ico {
log_not_found off; access_log off;
}
location = /robots.txt {
log_not_found off; access_log off; allow all;
}
location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
expires max;
log_not_found off;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_index index.php;
}
}
ON nginx I configured this role :
On server file:
location ~ .php$ {
root /var/www/public;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME /var/www/public$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# On Domain file
location /support {
try_files $uri $uri/ /index.php;
autoindex on;
autoindex_exact_size off;
}
#for admin panel
location ^~ /support/admin {
try_files $uri $uri/ /admin/index.php;
autoindex on;
autoindex_exact_size off;
}
I solved 403 error problem when I added autoindex on; line,
but I see "index of support" message when I Click on my Domain
and when I want to Click on index.html file, this file not to show, and instead of it, download is done.
How can I resolve this problem and What is my problem in my shared code
Try this
location /support {
default_type "text/html";
types { application/octet-stream html; }
…
}
I'm having trouble setting up two locations in my Nginx conf file.
I had no problem having two locations before adding one with an alias.
Location / with alias doesn't work.
Location /dev without alias works.
I would like to use two aliases because I have two folders : prod and dev.
Here is my current conf :
server {
listen 80;
listen [::]:80;
server_name domain.com www.domain.com;
root /home/domain/public_html/www/;
index index.html index.htm index.php index2.php;
location / {
alias /home/domain/public_html/www/prod/;
try_files $uri $uri/ /index.php?q=$uri&$args;
}
location /dev {
try_files $uri $uri/ /index.php?q=$uri&$args;
}
location ~* \.php$ {
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
}
charset utf-8;
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
location ~ /\.ht {
deny all;
}
}
What is happening is that accessing domain.com/dev/ works great but as soon as it's on the / location, I get a "no input file specified" error.
If I enter domain.com/license.txt, I can see Wordpress's license file.
If I try domain.com/index.php, I get the error.
I'm already using $request_filename to avoid root vs alias problems, any idea ?
You do not need to use alias in this scheme, but if you wish to run PHP with two separate roots, you will need to use a nested location block.
For example:
root /home/domain/public_html/www/prod;
location / {
try_files $uri $uri/ /index.php?q=$uri&$args;
}
location ~* \.php$ {
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
}
location ^~ /dev {
root /home/domain/public_html/www;
try_files $uri $uri/ /dev/index.php?q=$uri&$args;
location ~* \.php$ {
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
}
}
The first two location blocks are your /prod/ configuration, with the correct root to resolve URIs like /index.php.
The last location and nested location blocks are your /dev/ configuration. The root is set to the correct value to resolve URIs like /dev/index.php.
See this document for more.