My frontend is a static site served at location /, while my backend is a REST API at location /core/. I've configured nginx.conf to reverse proxy the backend, but according to the logs, it's attempting to serve it as a static site.
2018/12/17 08:47:32 [error] 6#6: *12 open() "/usr/share/nginx/html/core/v1/api/user/login" failed (2: No such file or directory)
Here is my nginx.conf:
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;
server {
listen 80;
server_name _;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
root /usr/share/nginx/html;
location ^~ /core/ {
proxy_pass http://my-named-backend:8080/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Port $server_port;
proxy_set_header X-Real-IP $remote_addr;
}
location / {
# Nothing to put here since the dist/ files are
# /usr/share/nginx/html is automatically served.
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
}
What's happening, and how can this be fixed?
Related
I'm running a flask_socketio server using gunicorn and eventlet behind nginx.
/etc/nginx/nginx.conf
daemon off;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
listen 80;
listen [::]:80;
root /docker/app/public;
location / {
# Return the file if found, otherwise goto the #websocket location
try_files $uri #websocket;
}
location #websocket {
proxy_buffering off;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_cache_bypass $http_upgrade;
proxy_pass http://localhost:5000;
}
}
}`
There are two problems with this configuration.
Accessing http://serverip/ returns 404, but http://serverip/index.html works as expected.
The websocket connection fails with
Error WebSocket connection to 'ws://serverip/socket.io/?EIO=4&transport=websocket&sid=bvsTNP3zXgW_DNBGAAAC' failed: Stack table collapsed
Any idea what's going on here?
I'm trying to use Nginx as a reverse proxy in and centos 6.9_64 environment where clients connects to my server (http://www.51ti.vip).
Nginx will forward all requests to other backend server. The communication is working on port 80.
However, once proxy_set_header XXXXX is set, it will appear 403 when accessed.
There is no relevant error information in /var/log/nginx/error.log.
Where's the problem?
Page 403 Forbidden
You don't have permission to access the URL on this server.
Note:
OS System: CentOS 6.9_64
Nginx version 1.10.2
Config:
/etc/nginx/nginx.conf as follows:
user root;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /var/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"';
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;
}
/etc/nginx/conf.d/default.conf as follows:
server {
listen 80 default_server;
server_name 47.75.249.199 "";
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
proxy_pass http://sq.otherserver.com;
#Proxy Settings
proxy_redirect off;
#proxy_set_header Host $host;
#proxy_set_header X-Real-IP $remote_addr;
#proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
The original problem was caused by "proxy_set_header Host $host",
there's no problem whith proxy_set_header X-Real-IP and proxy_set_header X-Forwarded-For.
But still don't understand why?
Nginx: when to use proxy_set_header Host $host vs $proxy_host
Module ngx_http_proxy_module
i am getting nginx error when I am trying to configure nginx on prometheus using https secure connection
below is my nginx.conf file
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /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/conf.d/*.conf;
server {
listen 80 default_server;
server_name nginxserver.com;
root /usr/share/nginx/html;
location / {
proxy_pass http://10.23.45.6:31866;
auth_basic "Prometheus";
auth_basic_user_file ".htpasswd";
proxy_buffering off;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
}
Can any one help me here what is going wrong .
I host some websites with Node.js and use Nginx to make it so that I can host multiple sites on the same server. I've just started getting this problem where if, for example, I go to examplesite1 it works fine and if I go to www.examplesite1 it works fine aswell and if I go to examplesite2 it works fine but when I go to www.examplesite2 it shows the content from examplesite1 on it. Here is the config I'm using:
nginx.conf:
user nginx;
worker_processes 1;
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;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
server_names_hash_bucket_size 64;
}
conf.d/blog.jakewalker.xyz.conf:
server {
listen 80;
server_name blog.jakewalker.xyz;
location / {
proxy_pass http://ghost:2368; # this is to a docker container
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
conf.d/jakewalker.xyz.conf:
server {
listen 80;
server_name jakewalker.xyz;
location / {
proxy_pass http://sites:2100; # also for a docker container
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
I followed this guide https://www.digitalocean.com/community/tutorials/how-to-host-multiple-node-js-applications-on-a-single-vps-with-nginx-forever-and-crontab on how to set it up.
I'm not sure if it'll help but here is my DNS for my website:
A jakewalker.xyz {ip of server}
CNAME www.jakewalker.xyz #
A blog.jakewalker.xyz {ip of server}
Am I doing anything wrong?
I need to install a uWSGI app and Kibana4 / elastic search stack on the same server. The uwsgi app only needs to be used when a user accesses the server via [server_IP]/charts/ and I'd like Kibana4 to be accessed via [Server_IP].
Both listen on port 80 via their own separate conf files and, predictably, the uwsgi app doesn't allow for Kibana4 to receive requests.
How would I adjust my conf files to allow the access I need? I'm a bit confused as to what I need to use (rewrite, redirect, something else?)
Thanks for your time
nginx_conf_for_uwsgi:
server {
server_name 192.168.250.37;
listen 80;
root /usr/local/wsgi;
access_log /var/log/nginx/graph_server/access.log;
error_log /var/log/nginx/graph_server/error.log;
client_max_body_size 500M;
proxy_read_timeout 600;
location / {
include uwsgi_params;
uwsgi_pass 192.168.250.37:9091;
uwsgi_read_timeout 600;
}
}
kibana4.conf:
server {
listen 80;
server_name 192.168.250.37;
#auth_basic "Restricted Access";
#auth_basic_user_file /etc/nginx/htpasswd.users;
location / {
proxy_pass http://192.168.250.37:5601;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
nginx.conf:
user nginx;
worker_processes 4;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
index index.html index.htm;
# Increase header buffer size (needed for PHP)
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
# Update the logs to display the real IP address after removing the IP for
# the load balancers
set_real_ip_from redacted; # a
set_real_ip_from redacted; # b
real_ip_header X-Forwarded-For;
real_ip_recursive on;
# Custom logger to display the subdomain folder (if applicable)
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
log_format log_thing '$remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent" '
'"$http_x_forwarded_for" sub:"$subdomain"';
log_format i_server '$remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'filename:"$http_filename"';
access_log /var/log/nginx/access.log main;
sendfile on;
keepalive_timeout 65;
include /etc/nginx/conf.d/*.conf;
server {
listen 80 default_server;
server_name localhost;
root /usr/share/nginx/html;
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 {
}
}
}
One way is to use nginx as a reverse proxy which is effectively what you are doing already. This way you have one nginx virtual host listening on port 80 which forwards different locations to separate nginx vhosts listening on different ports on your system.
You nginx reverse proxy vhost would look something like this, the 3 proxy_set_header lines can be moved to the server block if all locations work with them
server {
listen 80;
server_name 192.168.250.37;
port_in_redirect off
location / {
proxy_pass http://127.0.0.1:8081;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /charts {
proxy_pass http://127.0.0.1:8082;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
Then change you Kibanaconf to listen on port 8081 and uwsgi to listen on 8082
Alternatively you can combine the two vhosts into one and will need to set custom aliases for the root folders under each location and rearrange.
server {
listen 80;
server_name 192.168.250.37;
root /usr/local/wsgi;
client_max_body_size 500M;
proxy_read_timeout 600;
#auth_basic "Restricted Access";
#auth_basic_user_file /etc/nginx/htpasswd.users;
location / {
proxy_pass http://192.168.250.37:5601;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
location /charts {
include uwsgi_params;
uwsgi_pass 192.168.250.37:9091;
uwsgi_read_timeout 600;
}
}