I'm having a problem with my website.The site is down error "502 Bad Gateway" from nginx. I restarted the server and there are no errors. The site ran for months and now there is this error.
The node app is still running. Nothing changes there. The website is hosted on digitalocean and everything seems fine.
Site is located home/naoufal/mlg not inside www
app.js
var port = process.env.PORT || 8888;
sites-available/default
server {
root /usr/share/nginx/www;
index index.html index.htm;
# Make site accessible from http://localhost/
server_name localhost;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to index.html
try_files $uri $uri/ /index.html;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
location /doc/ {
alias /usr/share/doc/;
autoindex on;
allow 127.0.0.1;
deny all;
}
}
nginx.config
user www-data;
worker_processes 4;
pid /var/run/nginx.pid;
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
##
# nginx-passenger config
##
# Uncomment it if you installed nginx-passenger
##
#passenger_root /usr;
#passenger_ruby /usr/bin/ruby;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
What's wrong?
Thanks.
Edit: The site is now working for no particular reason. I think it was a problem with Digital Ocean not on the code itself.
Related
Could you please advice what is wrong with my Nginx configuration?
When I try "curl localhost:80" the response is the start nginx page, so it doesn't proxy traffic. I have checked the nginx documentation but I have no idea about this behavior. Have anybody an idea?
Here are the configuration files:
sites-enabled/default.conf
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name _;
location / {
set $ups tst;
proxy_pass http://$ups:8080/;
proxy_set_header Host $http_host;
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
}
nginx.conf
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
daemon off;
events {
worker_connections 768;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
include conf/upstream.conf;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
conf/upstream.conf
upstream tst {
server xxx.xxx.xxx.xxx;
server xxx.xxx.xxx.xxx;
}
Thanks in advance!
I have a problem on my Virtual Private Server : I already configured a "main" website which works fine, but I recently tried to create a sub domain and I am going to the "Welcome to nginx" every time I try to reach it. Here are my configuration files :
sub.domain.com (in /etc/nginx/sites-available)
server {
listen 80;
server_name sub.domain.com www.sub.domain.com;
root /home/user/www/sub;
index index.php index.html index.htm index.nginx-debian.html;
location / {
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/html;
}
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;
}
}
Nginx.conf (but should be good considering that it works for domain.com)
user www-data;
worker_processes 4;
pid /run/nginx.pid;
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
server_tokens off;
server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
#mail {
# # See sample authentication script at:
# # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
#
# # auth_http localhost/auth.php;
# # pop3_capabilities "TOP" "USER";
# # imap_capabilities "IMAP4rev1" "UIDPLUS";
#
# server {
# listen localhost:110;
# protocol pop3;
# proxy on;
# }
#
# server {
# listen localhost:143;
# protocol imap;
# proxy on;
# }
#}
And the file system at /home/user/
---- domain.com ... (more files)
|
user ---
| --- index.php
----sub --- --- addFile.php
--- files (empty)
--- data.xml
--- data.dtd
I don't know a lot about nginx config files I just copied the default one and modified the server name and the path, but this file seems to be okay so I'm still wondering why is this not working. Thank you for your help !
the active nginx configurations are made with symbolic links from /etc/nginx/sites-available/vhost.conf to /etc/nginx/sites-enabled/
ln -s /etc/nginx/sites-available/vhost.conf /etc/nginx/sites-enabled/
in sites-enabled you have a default active, that shows the nginx index (Welcome to nginx).
If you want delete it.
I recomend you to change your php-fpm pool to work for port
vim /etc/php/7.0/fpm/pool.d/www.conf
and change the line:
listen = /run/php/php-fpm.sock for listen = 127.0.0.1:9001 (or other port)
and restart the fpm, /etc/init.d/php-fpm restart
if you do a netstat -plnt it will show you the php-fpm working in port.
root#server# netstat -plnt
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:9001 0.0.0.0:* LISTEN 15230/php-fpm.conf)
and change your vhost in this way:
server {
listen 80;
server_name sub.domain.com www.sub.domain.com;
root /home/user/www/sub;
index index.php index.html index.htm;
location / {
#try_files $uri $uri/ =404;
try_files $uri $uri/ /index.php$args; #try with this
}
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_pass 127.0.0.1:9003; #your fpm port
fastcgi_index index.php;
fastcgi_buffer_size 128k;
fastcgi_buffers 8 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_read_timeout 300;
}
access_log /var/log/nginx/subdomain__access.log;
error_log /var/log/nginx/subdomain_error.log;
}#End server Block
When you have the new active configuration (symbolic link) on /etc/.../sites-enabled/
do
nginx -t
to run a test to see if the nginx configuration is good.
root#server:# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
If this is not working, check the log of the application and the nginx error log.
/var/log/nginx/error.log
/var/log/nginx/subdomain_error.log
(When the things are not working is where your sysadmin magic should come out)
Good luck!
I installed Windows Subsystem Ubuntu shell recently and shifted all of my development from XAMPP to nginx and php7.0-fpm installed through ubuntu windows subsystem.
The problem i am facing is that php files load extremly slower. For a test I simply put
<?php phpinfo(); ?>
in a file and executed it. It literally took the system two minutes to return the reply. I have debugged a lot but could not find any solution.
I am running nginx through nginx server blocks and have setup my local domains.
I am sure that php is slower by observing that if i load a static file i.e a txt or html files, it loads blazingly fast.
Below are my sites enabled files and nginx conf file ..
Sites Enabled
server {
listen 80 ;
listen [::]:80;
root /mnt/c/xampp/htdocs/doit/;
index index.html index.php;
server_name doit.dev www.doit.dev;
error_log /var/log/nginx/error.log;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_read_timeout 120;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location ~ /\.ht {
deny all;
}
}
Nginx Conf File:
user www-data;
worker_processes auto;
pid /run/nginx.pid;
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
#mail {
# # See sample authentication script at:
# # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
#
# # auth_http localhost/auth.php;
# # pop3_capabilities "TOP" "USER";
# # imap_capabilities "IMAP4rev1" "UIDPLUS";
#
# server {
# listen localhost:110;
# protocol pop3;
# proxy on;
# }
#
# server {
# listen localhost:143;
# protocol imap;
# proxy on;
# }
#}
Error logs for both nginx and php-fpm working, nothing being logged against errors.
Using windows 10 v1803, and nginx & php7 fpm via WSL.
Changing listen to 127.0.0.1:9000 doesn't work for me.
After spending hours of googling, I found:
https://github.com/Microsoft/WSL/issues/2100
i.e. Add
fastcgi_buffering off;
to nginx.conf, and save my day.
Sorted this out, pasting for any other enthusiast working with ubuntu on windows subsystem.
The default Nginx and php setups are going to use a unix:socket, but that’s not going to work for WSL. Also, WSL uses a lightweight init system and services are not going to start automatically for Nginx, PHP, MySQL, etc.
Edit /etc/nginx/sites-available/example.com.conf
comment out fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
and add fastcgi_pass 127.0.0.1:9000;
Edit /etc/php/7.0/fpm/pool.d/www.conf
comment out listen = /var/run/php/php7.0-fpm.sock;
and add listen = 127.0.0.1:9000;
It will fix all of your issues.
I have a medium to large size WordPress site running off a MediaTemple NGINX server, and CENTOS and I'm having trouble getting any location block properties applied. What the goal is, is to have a directory locked down so that only the server has access to it. From everything I've seen, the root I'm setting and the locations blocks are being called correctly, they just don't seem to be being noticed.
#user nginx;
worker_processes 24;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
# rewrite_log on;
include mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
sendfile on;
#tcp_nopush on;
keepalive_timeout 3;
#tcp_nodelay on;
#gzip on;
#gzip_disable "MSIE [1-6]\.(?!.*SV1)”;
index index.php index.html index.htm
server_tokens off;
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
include /etc/nginx/conf.d/*.conf;
include fastcgi.conf;
server {
listen 80;
server_name domainname.com;
rewrite ^ $scheme://www.domainname.com$request_uri redirect;
}
server {
listen 80;
server_name www.domainname.com;
root /var/www/vhosts/domainname.com/httpdocs;
# Additional rules go here.
location ^~ /protected-folder/ {
allow 127.0.0.1;
deny all;
}
# include global/restrictions.conf;
location ~* \.php$ {
try_files $uri =404; # This is not needed if you have cgi.fix_pathinfo = 0 in php.ini (you should!)
fastcgi_pass 127.0.0.1:9000;
}
# Only include one of the files below.
include global/wordpress.conf;
# include global/wordpress-ms-subdir.conf;
# include global/wordpress-ms-subdomain.conf;
}
}
After every change I'm running:
sudo service nginx restart
Do I have to do a full server reboot?
Is there something wrong with the syntax above?
For any imports above, the content follows almost identical to the WordPress article on setting up NGINX for WordPress.
Any help on this would be appreciated.
I have purchased New VPS from weloveservers provider . My VPS operating system is Centos 7 . My allocated IP is 192.3.108.207 . I have installed Nginx using ssh . Now i need to show something on my IP address . How can i point my IP to specific folder .. My current configuration for nginx is as follows ,
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
events {
worker_connections 1024;
}
http {
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
}
Here is my virtual.conf
server {
listen 80;
server_name 192.3.108.207;
root /var/www;
#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;
location / {
root /var/www;
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?$args;
}
}
You can specify the particular folder in your virtual.conf.
As you have mentioned in your virtual.conf root /var/www;
Instead of /var/www; , you can give the folder name and restart your nginx service.