I'm trying to setup NGINX server as benchmark to test client-server interaction. The root in the server contains a few thousand random html pages.
This is also my first work with applications like NGINX. I have been struggling to configure nginx for awhile now using this website [1] and the documentation of nginx.
To give you some more background, I setup nginx on my local machine and the installation on a specific-directory (called libs, bad naming -- I should change that.)
After starting nginx using ./sbin/nginx -c conf/nginx.conf I tried to curl on the website to check if it is functional
curl http://127.0.0.1:6011
And I get this error:
<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.15.10</center>
</body>
</html>
Where am I going wrong in my configuration?
[1] https://www.slashroot.in/nginx-web-server-performance-tuning-how-to-do-it
worker_processes 32;
worker_rlimit_nofile 51200;
error_log /lustre1/nginx-benchmark/libs/logs/error.log;
error_log /lustre1/nginx-benchmark/libs/logs/error.log notice;
error_log /lustre1/nginx-benchmark/libs/logs/error.log info;
pid /lustre1/nginx-benchmark/libs/logs/nginx.pid;
events {
worker_connections 50000;
multi_accept on;
}
http {
include /lustre1/nginx-benchmark/libs/conf/mime.types;
default_type application/octet-stream;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
tcp_nodelay on;
types_hash_max_size 2048;
#gzip on;
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 /lustre1/nginx-benchmark/libs/logs/access.log main;
server {
listen 6011 default_server;
listen [::]:6011 default_server ipv6only=on;
server_name localhost;
#listen 6011;
#server_name localhost;
#charset koi8-r;
access_log /lustre1/nginx-benchmark/libs/logs/host.access.log main;
location / {
root /lustre1/nginx-benchmark/dataset/1024/;
try_files $uri html/index.html;
#index.php;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /lustre1/nginx-benchmark/libs/html/50x.html {
root /lustre1/nginx-benchmark/libs/html;
}
}
}
Can you ls any files in /lustre1/nginx-benchmark/dataset/1024/?
ls -l /lustre1/nginx-benchmark/dataset/1024/
If you can't then, that's why nginx is 404ing your request - it can't see them either. If you can, what are the permissions on that folder and the files? Are they readable by the user nginx is running as? What about the parent folders of that path?
Add an error log with debug, to see what nginx thinks the problem is:
access_log /lustre1/nginx-benchmark/libs/logs/host.access.log main;
error_log /lustre1/nginx-benchmark/libs/logs/host.error.log debug;
Change your try_files line to look like this:
try_files $uri /index.html =404;
The =404 should terminate nginx's repeated checking, which is probably being caused by your /lustre1/nginx-benchmark/dataset/1024/ docroot not having a html/index.html in it.
Related
I am using centos 7 with python 2.7.15 and uwsgi + nginx to host my app.
step by step i am getting closer to make it work.
I had to set the python 2.7.15 to work as python insted of 2.7.5
then I had some uwsgi probmels with emperor service.
but now... the app works when I run uwsgi trough
uwsgi --http :8000 --chdir /opt/web2py -w wsgihandler:application
but when I try to put it together with nginx I cannot access the page
My nginx config ATM is
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
map $request_uri $loggable {
~/engine/getTasks.* 0;
~/static/* 0;
default 1;
}
access_log /var/log/nginx/access.log main if=$loggable;
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;
include /etc/nginx/conf.d/*.conf;
server {
client_max_body_size 10M;
listen 80 default_server;
listen [::]:80 default_server;
server_name localhost;
root /usr/share/nginx/html;
include /etc/nginx/default.d/*.conf;
location ^~ /.well-known/acme-challenge/ {
default_type "text/plain";
root /opt/web2py_cert/web2py.com;
}
location / {
uwsgi_pass unix:/run/uwsgi/web2py.sock;
include uwsgi_params;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
}
And my uwsgi.ini file
[uwsgi]
plugin = python2.7
logto = /opt/web2py/uwsgi.log
chdir = /opt/web2py
http = 0.0.0.0:80
module = wsgihandler:application
master = true
processes = 5
uid = woshi
socket = /run/uwsgi/web2py.sock
chown-socket = woshi:nginx
chmod-socket = 660
vacuum = true
any suggestions???
thank you
The problem
I have a website developed with NextJS, it is running on a server with Nginx. The website files are inside the public_html folder and running on port 3004, and i have a proxy_pass that redirect the requests to the NextJS website on port 3004.
But when I search for my domain or my site on google, it shows up in the results: Index of / (and the files inside)
I would like to remove this (and all the listing of files inside) to just put Home - Domain, for example.
Research and issue photos
My next.conf file
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
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;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 4096;
include /etc/nginx/mime.types;
default_type application/octet-stream;
include /etc/nginx/conf.d/*.conf;
server {
listen 80;
listen [::]:80;
server_name _;
root /usr/share/nginx/html;
include /etc/nginx/default.d/*.conf;
error_page 404 /404.html;
location = /404.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
server {
listen 80;
server_name computadorsolidario.tec.br www.computadorsolidario.tec.br;
location / {
autoindex off;
proxy_pass http://localhost:3004;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
}
}
}
How can i solve this?
You can turn off the feature of nginx where it creates directory listings:
autoindex off;
If you want to replace "index if /" with an actual home page, you would need to create an index.html file in document root directory.
You should also add as a last location in your conf
location ~ /\. {
deny all;
}
to block file access to dot files .env file or other sensitive data
I have 3 applications(one web application,2 angular apps) running on same ec2 instance on same port(8080)
Paths to apps are
http://53.233.23.12:8080/Abc
http://53.233.23.12:8080/Xyz
http://53.233.23.12:8080/Pqr
I am using Nginx for redirection in server
My nginx.conf file looks like this`
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http{
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;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
include /etc/nginx/conf.d/*.conf;
index index.html index.htm;
server {
listen 80 default_server;
listen [::]:80 default_server;
include /etc/nginx/default.d/*.conf;
server_name www.listmydebt.com listmydebt.com;
return 301 http://listmydebt.com:8080/Abc;
# redirect server error pages to the static page /40x.html
error_page 404 /404.html;
location = /40x.html {
}
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
server {
listen 80;
server_name admin.listmydebt.com;
return 301 http://listmydebt.com:8080/Xyz;
}
server {
listen 80;
server_name partner.listmydebt.com;
return 301 http://listmydebt.com:8080/Pqr;
}
}
All domain and subdomains( listmydebt.com, admin.listmydebt.com , partner.listmydebt.com) pointing to same IP address(53.233.23.12).
My Nginx is running on port 80 and tomcat server in which my applications are deplyed running on port 8080
When I put listmydebt.com its redirecting to http://listmydebt.com:8080/Abc and browser url changed(http://listmydebt.com:8080/Abc). But what I want is the url on browser should remain same as listmydebt.com but it should show the redirected url content.same happening for subdomains as well.
Please help me out .If any additional info is required please mention.Thanks in advance.
The best way is to use docker swarm, or at least run the applications as several dockers in several ports.
Then you can easily map the ports on subdomains with an ansible playbook.
I am currently working on a small website in my free time. For development, I keep all git repositories in ~/git. Is it possible to configurate nginx so that if I go to localhost/A or localhost/B, it would use ~/git/A and ~/git/B respectively?
I am using fedora and tried with a single repo, but I keep getting 404:
/etc/nginx/nginx.conf
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
events {
worker_connections 1024;
}
http {
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;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
server {
listen 80;
server_name localhost;
root /home/MartenBE/git/;
index index.html index.php;
location /A/ {
alias /home/MartenBE/git/A/;
}
}
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
}
I think only following should work for you.
server {
listen 80;
server_name localhost;
root /home/MartenBE/git/;
index index.html index.php;
}
You don't need to add location module because you have already defined root. Now if you try localhost/A/index.html, Nginx will try to find it under /home/MartenBE/git/A/index.html.
What are the requests you are trying ?
First of all it is good to seperate site configuration from main nginx conf file.
Do the following..
Remove all server blocks from /etc/nginx/nginx.conf.
create a file in /etc/nginx/sites-available/yourconf with the following content.
server {
listen 80;
server_name localhost;
root /home/MartenBE/git/;
index index.html index.php;
}
Create a symlink to the config file inside /etc/nginx/sites-enabled/yourconf.
Remove /etc/nginx/sites-enabled/default & reload the nginx config.
NOTE: if you are using ubuntu run sudo service nginx reload
What I am trying to do using nginx is- to call a backend for authentication and if the response is successful I will redirect to website 1 (for example -google.com) and if authentication fail I will redirect to website2(facebook for example).
Below is my nginx.conf-
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log;
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;
keepalive_timeout 65;
# Load config files from the /etc/nginx/conf.d directory
# The default server is in conf.d/default.conf
include /etc/nginx/conf.d/default.conf;
}
The default.conf file is as below -
server {
listen 80 default_server;
server_name _;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
# root /usr/share/nginx/html;
# index index.html index.htm;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_pass http://backend_ip_Address;
set $my_var 0;
if ($status = "200"){
set $my_var 1;
}
#if($status = 4xx) {
# set $my_var 2;
#}
if ($my_var = 1){
proxy_pass http://www.google.com;
}
if ($my_var = 2) {
proxy_pass http://www.facebook.com;
}
}
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;
}
}
The issue I am facing is when I am trying to execute sudo service nginx restart with this configuration I am getting below error-
Starting nginx: nginx: [emerg] unknown "status" variable
The same $status is also present in nginx.conf log configuration and it's logging the response code properly like 301, 200 etc. But the same status variable is not working in default.conf file. Any help on what I am doing wrong?
I tried replacing status with body_bytes_sent header and it's works.
By google search https://www.google.co.in/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=nginx++unknown+%22status%22+variable only related information is https://www.drupal.org/node/2738983 but no much help to resolve this.
status variable is defined on very late phase, after request is processed and response is ready to sent back.
You cannot use it for conditional routing.
Usually it's used for logging.
Here you may read about nginx directives execution order and phases:
https://openresty.org/download/agentzh-nginx-tutorials-en.html