Nginx on vagrant not loaded assets for symfony2 - php

I have problem with my website, all assets(css,js,fonts) not loaded.
My configuration :
server {
listen 80;
server_name shop.dev;
index index.php index.html index.htm;
access_log /var/log/nginx/test.dev.access.log;
error_log /var/log/nginx/test.dev.error.log;
location / {
#index app_dev.php;
#try_files $uri /app_dev.php?$args;
try_files $uri /app_dev.php$is_args$args;
}
location ~ .php$ {
root /home/vagrant/Workspace/shop/web;
index index.html index.htm index.php;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_param APPLICATION_ENV development;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
}
sendfile off;
}
I use vagrant machine. Exist a solution? Help me please!!

Related

Laravel, Docker and Nginx: 404 for all files in /public folder

I created a new project in Laravel 7 by using docker-compose 3.3 and Nginx 1.17.
The enpoints created on Laravel works well, the problem comes when I try to access to whatever static asset in the '/public' folder. I tried with .css and .js files and also with the robots.txt but Laravel returns a 404 not found error.
This is my nginx.conf (taken from https://laravel.com/docs/7.x/deployment#nginx)
events {
}
http {
server {
server {
listen 80;
server_name localhost;
root /var/www/app/public;
index index.html index.htm index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_pass app:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
}
}
I tried different fixes found on forums and on Stackoverflow, like recompiling files, clear the cache... But nothing works.
Can you spot the problem?
can you try the following config:
server {
listen 80;
index index.php index.html;
server_name localhost;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /var/www/html/public;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}

Nginx setup for laravel project, which has routes with ".php" endings

I'm trying to setup my Laravel project using Nginx. My /etc/nginx/conf.d/default.conf is:
server {
listen 80;
index index.php index.html;
root /var/www/public;
location / {
try_files $uri /index.php?$args;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass app:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
I have a problem with routes with ".php" endings, e.g.
Route::get('modules.php', 'ModuleController#index');
Instead of going to index.php and looking there the route, the server tries to open file modules.php, which doesn't exist.
I know, that problem in nginx settings, but I don't have experience with it, so I can't fix it myself.
Look through this page https://www.digitalocean.com/community/tutorials/how-to-install-laravel-with-an-nginx-web-server-on-ubuntu-14-04
Here you can find suitable configuration and description.
For example:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /var/www/laravel/public;
index index.php index.html index.htm;
server_name server_domain_or_IP;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass app:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Add a try_files statement to the second location block.
For example:
location / {
try_files $uri /index.php?$args;
}
location ~ \.php$ {
try_files $uri /index.php?$args;
fastcgi_pass app:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}

Nginx change the root location to wordpress site

Currently I have a Wordpress site under /var/www/html/wordpress and other php projects under /var/www/html/projects. I want my root location to point to wordpress one. Here is my current nginx config:
server {
listen 80 default_server;
server_name _;
set $yii_bootstrap "index.php";
root /var/www/html;
client_max_body_size 2M;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location /projects/inspection/ {
root /var/www/html;
try_files $uri /index.php$is_args$args;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
}
location /projects/ {
root /var/www/html;
index index.html $yii_bootstrap;
try_files $uri $uri/ /$yii_bootstrap?$args /index.php$is_args$args;
}
location / {
root /var/www/html/wordpress;
try_files $uri $uri/ =404;
index index.php index.html index.htm;
}
location ~ \.php{
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_pass php-fpm;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
include fastcgi_params;
}
error_page 404 /404.html;
location = /40x.html {
}
}
But it returns 404. I tried to put alias instead and it returns 403 forbidden. How should I handle this?

Ubuntu 16.04, nginx, phpmyadmin - 502 Bad Gateway

I am using this setting for nginx (default file):
server {
listen 30425;
# Don't want to log accesses.
#access_log /dev/null main;
access_log /var/log/nginx/php.acces_log main;
error_log /var/log/nginx/php.error_log info;
root /usr/share/phpmyadmin;
index index.php index.html index.htm;
error_page 401 403 404 /404.php;
location ~ .*.php$ {
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SERVER_NAME $http_host;
fastcgi_ignore_client_abort on;
}
}
When I try to access 30425, I am getting 502 Bad Gateway. All other setting are default one (PHP 7).
I had to replace this fastcgi_pass 127.0.0.1:9000;
to fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
and then it worked perfectly.
Full code.
server{
listen 80;
index index.html index.htm index.php;
server_name 127.0.0.1;
root /usr/share/phpmyadmin;
location / {
#try_files $uri $uri/ = 404;
autoindex on;
}
location ~\.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+);
try_files $uri $uri/ =404;
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_na$
fastcgi_param SERVER_NAME $http_host;
fastcgi_ignore_client_abort on;
}
}

Nginx index module not point to index.php

My problem is access main site: example.com not point to index.php, i have to manually enter full url example.com/index.php.
Subdomain sub01.example.com working well, automatic point to index.php.
I've 3 site as bellow, please help to check
main site: example.com
subdomain: sub01.example.com, sub02.example.com
and this is my configure:
server {
listen 80;
server_name www.example.com;
return 301 $scheme://example.com$request_uri;
}
server {
listen 80;
server_name example.com;
# root directive should be global
root /var/www/example.com/;
index index.php;
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.php?$args;
}
location ~ \.php$ {
try_files $uri =404;
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
server {
listen 80;
server_name sub01.example.com www.sub01.example.com;
# root directive should be global
root /var/www/sub01.example.com/;
index index.php;
access_log /var/www/sub01.example.com/nginx_access.log;
error_log /var/www/sub01.example.com/nginx_error.log;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
try_files $uri =404;
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
server {
listen 80;
server_name sub02.example.com www.sub02.example.com;
# root directive should be global
root /var/www/sub02.example.com/;
index index.php;
access_log /var/www/sub02.example.com/logs/nginx_access.log;
error_log /var/www/sub02.example.com/logs/nginx_error.log;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
try_files $uri =404;
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
I'm sorry.
This configuration was fine.
Error come from cloudflare DNS pointer config.

Categories