The images are breaking on web pages hosted on nginx server - javascript

I have configured NGINX server on Centos 6.4 everything is working fine with my NGINX server but when i updated the another build in root directory then first time the web pages load successfully but when i refreshed the pages then my images and text from web pages are breaking. In root directory I have multiple builds.
/usr/share/nginx/html/build1
My nginx configuration is as fallows
user nginx;
worker_processes 2;
error_log /var/log/nginx/error.log;
#error_log /var/log/nginx/error.log notice;
#error_log /var/log/nginx/error.log info;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#keepalive_timeout 65;
proxy_buffers 30 32k;
proxy_busy_buffers_size 64k;
# Load config files from the /etc/nginx/conf.d directory
# The default server is in conf.d/default.conf
include /etc/nginx/conf.d/*.conf;
gzip on;
gzip_comp_level 6;
gzip_vary on;
gzip_min_length 1024;
gzip_proxied any;
gzip_types text/plain text/css application/json application/x-javascript te$
gzip_buffers 16 8k;
}
and
default.conf file
server {
listen 8080 default_server;
server_name _;
root /usr/share/nginx/html;
# location ~* .(jpg|jpeg|png|gif|ico|css|js)$ {
# expires 365d;
# }
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
index index.html index.htm;
}
error_page 404 /404.html;
location = /404.html {
root /usr/share/nginx/html;
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
Please suggest where i am going wrong

Related

Livewire is not defined

I am having an issue deploying my Laravel Livewire project to the server. The issue is that livewire.js file is not accessible and showing an error in the console
Livewire is not defined
My server environment is LNMP. I am using Nginx instead of apache. There is an alternate way to fix this by publishing livewire which copies files from vendor folder to resources folder. By you have to maintain js files yourself after that and i don't want to do that.
It may be caused by Nginx by blocking js response files, How can I fix this
This is my nginx config file
user www www;
worker_processes auto;
error_log /www/wwwlogs/nginx_error.log crit;
pid /www/server/nginx/logs/nginx.pid;
worker_rlimit_nofile 51200;
events
{
use epoll;
worker_connections 51200;
multi_accept on;
}
http
{
#AAPANEL_FASTCGI_CONF_BEGIN
fastcgi_cache_key "$scheme$request_method$host$request_uri";
fastcgi_cache_path /dev/shm/nginx-cache/wp levels=1:2 keys_zone=WORDPRESS:100m inactive=60m max_size=1g;
fastcgi_cache_use_stale error timeout invalid_header http_500;
fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
#AAPANEL_FASTCGI_CONF_END
include mime.types;
#include luawaf.conf;
include proxy.conf;
default_type application/octet-stream;
server_names_hash_bucket_size 512;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 50m;
sendfile on;
tcp_nopush on;
keepalive_timeout 60;
tcp_nodelay on;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 256k;
fastcgi_intercept_errors on;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_types text/plain application/javascript application/x-javascript text/javascript text/css application/xml;
gzip_vary on;
gzip_proxied expired no-cache no-store private auth;
gzip_disable "MSIE [1-6]\.";
limit_conn_zone $binary_remote_addr zone=perip:10m;
limit_conn_zone $server_name zone=perserver:10m;
server_tokens off;
access_log off;
server
{
listen 888;
server_name phpmyadmin;
index index.html index.htm index.php;
root /www/server/phpmyadmin;
location ~ /tmp/ {
return 403;
}
#error_page 404 /404.html;
include enable-php.conf;
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location ~ /\.
{
deny all;
}
access_log /www/wwwlogs/access.log;
}
include /www/server/panel/vhost/nginx/*.conf;
}
livewire.js does not change as much, unless there is a change in composer.json regarding laravel-livewire package, i suggest you just publish your livewire.js file using
php artisan livewire:publish --assets
And then adding auto publishing script
{
"scripts": {
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"#php artisan package:discover --ansi",
"#php artisan vendor:publish --force --tag=livewire:assets --ansi"
]
}

How to serve static files (css, js, img) with NGINX and Node.js

I'm trying to serve css, img and js static files from my public directory (I don't have any html in this directory), so for that I configured my nginx server directive like this:
server {
listen 80;
listen [::]:80;
server_name my-site.com;
root /home/myuser/site/public;
location / {
proxy_pass "http://localhost:3000";
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
But nginx server grabs all requests for "/" and tries to give me static files, so I don't see my index.html from node. How to render my index.html on "/" route?
You can solve this easily with the following Nginx config.
Nginx Config
server {
listen 80;
listen [::]:80;
server_name my-site.com;
location / {
proxy_pass "http://localhost:3000";
}
location /public {
root /PATH_TO_YOUR_NODE_APP_PUBLIC_DIRECTORY
expires 30d;
}
}
In your express app .html files access these static files with /public prefix. Example: 'http://sample.com/public/app.css'
If you are using express, you only need to configure express.static. Docs: https://expressjs.com/en/starter/static-files.html
If you want to configure it from nginx add a layer to your path like this.
server {
listen 80;
listen [::]:80;
server_name my-site.com;
root /home/myuser/site/public;
location / {
try_files $uri $uri/ #nodejs;
}
location #nodejs {
proxy_pass "http://localhost:3000";
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}

Javascript - how to play french files?

i have french audio files (a lot of with accent, space, symbols), for example:
à l'étranger.wav
I need to play that file in chromium or google chrome as below, in meeting demo:
input = "à l'étranger.wav";
$('#mediaplayer').prop('loop', false);
$('#mediaplayer').attr('src', 'http://localhost/' + input).show();
mediaplay= document.getElementById('mediaplayer');
mediaplay.play();
When i use that same code for other files it works, but never worked when its with the file contain abnormal french characters? how can i play it without renaming the original file name?
EDIT: nginx runnning as localhost with following config:
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}

Nginx Server break images on web browser after refreshed 3 to 4 times

Hi I am in very confusing state now. I have configured Nginx 1.6 on Centos 6 for serving only Code (js, css, html) pages all other images coming and calls happened through load balancer.
My problem is when I load the page on web browser the first time it will take time and then i refreshed the page 3 to 4 times the images/words are breaking such as akki shown as __akki__ how do i know where its cached and how do i solve this problem my configuration as shown below
user nginx;
worker_processes 12;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
proxy_buffers 30 32k;
proxy_busy_buffers_size 64k;
keepalive_timeout 65;
gzip on;
gzip_comp_level 6;
gzip_vary on;
gzip_min_length 1024;
gzip_proxied any;
gzip_types text/plain text/css application/json application/x-javascript te$
gzip_buffers 16 8k;
open_file_cache max=10000 inactive=30s;
open_file_cache_valid 60s;
open_file_cache_min_uses 2;
open_file_cache_errors on;
include /etc/nginx/conf.d/*.conf;
}
default.conf
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}

Redirect to https not working (and https itself not working)

My goals are to get https to work, and then get the http to https redirections, and the non-www to www redirections to work.
Nginx.conf looks like:
http {
include mime.types;
default_type application/octet-stream;
types_hash_max_size 2048;
server_names_hash_bucket_size 64;
include site.conf;
server {
listen 8080;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
}
}
site.conf looks like:
upstream site_local {
server 127.0.0.1:9090 max_fails=3 fail_timeout=20s;
}
server {
listen 80;
server_name site.com;
return 301 https://www.site.com$request_uri;
}
server {
listen 80;
server_name www.site.com;
return 301 https://www.site.com$request_uri;
}
server {
listen 443;
server_name www.site.com;
set $app_root /home/site/site-web-node/public;
ssl on;
ssl_certificate /etc/ssl/SSL.crt;
ssl_certificate_key /etc/ssl/site.key;
location / {
proxy_pass https://site_local;
client_max_body_size 10m;
client_body_buffer_size 128k;
}
location ~ /(app|lang|js) {
root $app_root;
}
}
service nginx reload is successful, however the website's https isn't working, nor the redirects. http is working as before.
nginx -t returns successful.
I am getting the same error
Its show me like this when i run sudo netstat -tlnp | grep 443
tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN 10031/nginx
Then i found it was the site available server config file was the problem. Its working now.

Categories

Resources