I successfully deploy my Laravel app to in digital ocean, but my CSS & JS file are 403 (Forbidden), inside my console it show me error of net::ERR_ABORTED 403 (Forbidden)
how can I give permission to my CSS &JS in my nginx on digital ocean?, any help
nginx config
// nginx configuration
server {
listen 80;
server_name DOMAIN_NAME_OR_IP_ADDRESS;
root /var/www/name_of_repo/public;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
index index.html index.htm index.php;
charset utf-8;
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:/var/run/php/php7.4-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /.(?!well-known).* {
deny all;
}
}
Related
This is my nginx config:
server {
listen 80;
listen [::]:80;
server_name test.com;
root /var/www/test.com/public;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";
index index.php;
charset utf-8;
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$ {
#include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.2-fpm.sock;
#fastcgi_pass unix:/var/run/php/php8.0-fpm.sock;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
}
eveything is working except my url keeps displaying like this:
http://test.com/build` instead of `http://test.com/
http://test.com/build/profile/2` instead of `http://test.com/profile/2
is there a problem in my configuration?
and the worst part is when I try to refresh browser the page it returns 404.
Thank you!
I'm using Laravel 8 for my project.
Php: 7.4
Using AWS Nginx Server
My Application's Homepage is fine. The homepage is working well. But, when I'm clicking a link then I'm getting a 404 Not Found error from Nginx.
Here is my server config in nginx.conf
server {
listen 80;
listen [::]:80;
server_name something.com;
root /srv/something.com;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";
index index.php;
charset utf-8;
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:/var/run/php/php7.4-fpm.sock;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
}
What to do? What to change?
How to fix this error?
I am facing a problem where try_files can't recognize static files in my root directory.
I have already checked my root, which is /var/www/public , all the CSS and js files are inside this directory and is not empty. However, nginx fails to recognize and serve my files. It fails to recognize the files, so it passed the request to the .php location block to process uri, which I don't want. I want it to serve the static files directly. Therefore, I would like to check is nginx looking at the same root directory as I think.
Is there any way I can check what is in the directory that nginx check for files? or any way I can figure out what's the problem?
Here is my nginx.conf:
server {
server_name example.com;
listen 80 ;
access_log /var/log/nginx/access.log vhost;
return 301 https://$host$request_uri;
}
server {
server_name example.com;
listen 443 ssl http2;
access_log /var/log/nginx/access.log vhost;
error_log /var/log/nginx/error_log;
include /etc/nginx/mime.types;
root /var/www/public;
ssl_certificate {ssl_certificate location};
ssl_certificate_key {ssl_certificate_key location};
add_header Strict-Transport-Security "max-age=31536000" always;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
index index.php;
charset utf-8;
location / {
root /var/www/public;
try_files $uri $uri/ /index.php?$is_args$args;
}
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_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass {my_container_name}:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
Please note that I have changed the server name, ssl_certificate info and docker container name for privacy purpose.
I am answering my own question.
The problem was I didn't mount my app volume(the volume that has all code&resources in it) to my nginx container.
Problem solved after I mounted the volume.
How to configure Orchid control panel, and nginx if needed, so that Orchid loads the javascript and css files?
Under ubuntu 18.04 running vesta control panel, Orchid does not load the javascript and css content at somesite.com/dashboard.
Since nginx properly loads the css and javascript at the somesite.com/ it appears that the nginx conf is not causing it.
Any help would be greatly appreciated.
/home/user/conf/web/somesite.com.nginx.conf:
server {
listen some-server-ip:443 ssl;
server_name somedomain.com www.somedomain.com;
root /home/user/web/somedomain.com/public;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
index index.php index.html index.htm;
access_log /var/log/nginx/domains/somedomain.com.log combined;
access_log /var/log/nginx/domains/somedomain.com.bytes bytes;
error_log /var/log/nginx/domains/somedomain.com.error.log error;
ssl_certificate /home/user/conf/web/ssl.somedomain.com.pem;
ssl_certificate_key /home/user/conf/web/ssl.somedomain.com.key;
location / {
# added the following line to allow nginx to recognize laravel dynamically created directories
try_files $uri $uri/ /index.php?$query_string;
location ~* ^.+\.(jpeg|jpg|png|gif|bmp|ico|svg|css|js)$ {
expires max;
}
location ~ [^/]\.php(/|$) {
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
fastcgi_pass 127.0.0.1:9002;
fastcgi_index index.php;
include /etc/nginx/fastcgi_params;
}
}
error_page 403 /error/404.html;
error_page 404 /error/404.html;
error_page 500 502 503 504 /error/50x.html;
location /error/ {
alias /home/user/web/somedomain.com/document_errors/;
}
location ~* "/\.(htaccess|htpasswd)$" {
deny all;
return 404;
}
location /vstats/ {
alias /home/user/web/somedomain.com/stats/;
include /home/user/conf/web/somedomain.com.auth*;
}
include /etc/nginx/conf.d/phpmyadmin.inc*;
include /etc/nginx/conf.d/phppgadmin.inc*;
include /etc/nginx/conf.d/webmail.inc*;
include /home/user/conf/web/snginx.somedomain.com.conf*;
}
Orchid relies entirely on Laravel settings
server {
listen 80;
server_name example.com;
root /example.com/public;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
index index.html index.htm index.php;
charset utf-8;
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:/var/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
}
Pay attention to the documentation.
Solution: orchid.software/en/docs/installation > Publishing resources: php artisan orchid:link.
NGINX LOG
Chrome Network
I set nginx.
Routing has no problem.
css and js do not load.
It seems that only indexes are recognized in public folders.
I do not know what I missed or what the typo was.
server {
listen 80;
server_name laravel.test;
root /var/www/laravel/public;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~* \.(?:css|js)$ {
expires 1y;
access_log off;
add_header Cache-Control "public";
}
location ~* \.(?:ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc|webp|swf)$ {
expires 1y;
access_log off;
add_header Cache-Control "public";
}
index index.html index.htm index.php;
charset utf-8;
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/html;
}
location ~ \.php$ {
fastcgi_pass php:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors off;
fastcgi_buffer_size 16k;
fastcgi_buffers 16 16k;
fastcgi_connect_timeout 600s;
fastcgi_send_timeout 600s;
fastcgi_read_timeout 600s;
}
location ~ /\.ht {
deny all;
}
access_log /var/log/nginx/laravel-access.log;
error_log /var/log/nginx/laravel-error.log error;
}
local php -S localhost:5000 It works well.
It does not seem to be a problem with the php code
++ ps
http://laravel.test 200
http://laravel.test/home 200
http://laravel.test/css/test.php 200
http://laravel.test/css/app.css 404
http://laravel.test/js/test.php 200
http://laravel.test/js/app.js 404