I have a VPS and NGINX on it and I am trying run a flask app and I want address of flask app be something like site.com/flask but location doesnt work for that, it only runs main Address site.com
server {
listen 80;
listen 443 ssl;
ssl_certificate /etc/letsencrypt/live/bot.itarashe.zone/cert.pem ;
ssl_certificate_key /etc/letsencrypt/live/bot.itarashe.zone/privkey.pem ;
ssl_trusted_certificate /etc/letsencrypt/live/bot.itarashe.zone/chain.pem ;
server_name bot.itarashe.zone www.bot.itarashe.zone ;
location = ~^/flask/ {
include proxy_params;
proxy_pass http://unix:/home/saeb/py/flask/myproject/myproject.sock;
}
location / {}
}
but if I remove ~^/flask
it works in main address
ssl_certificate /etc/letsencrypt/live/bot.itarashe.zone/cert.pem ;
ssl_certificate_key /etc/letsencrypt/live/bot.itarashe.zone/privkey.pem ;
ssl_trusted_certificate /etc/letsencrypt/live/bot.itarashe.zone/chain.pem ;
server_name bot.itarashe.zone www.bot.itarashe.zone ;
location / {
include proxy_params;
proxy_pass http://unix:/home/saeb/py/flask/myproject/myproject.sock;
}
}
I tried
location /flask {}
location /flask/ {}
location ~^/flask {}
location = ...
none of them didnt work,
access log is:
104.244.78.207 - - [27/Sep/2018:01:50:13 -0400] "GET /flask/ HTTP/1.1" 404 209 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:62.0) Gecko/20100101 Firefox/62.0"
and error log shows no error:
sudo tail -f /var/log/nginx/error.log
[sudo] password for saeb:
2018/09/27 00:15:50 [error] 2650#2650: *13 open() "/usr/share/nginx/html/robots.txt" failed (2: No such file or directory), client: 54.175.74.27, server: bot.itarashe.zone, request: "GET /robots.txt HTTP/1.1", host: "bot.itarashe.zone"
2018/09/27 00:27:23 [error] 2650#2650: *16 open() "/usr/share/nginx/html/robots.txt" failed (2: No such file or directory), client: 66.249.66.76, server: bot.itarashe.zone, request: "GET /robots.txt HTTP/1.1", host: "oldflight.ir"
2018/09/27 00:27:23 [error] 2650#2650: *17 open() "/usr/share/nginx/html/assets/font/IranSans/IRANSans-Medium-web.woff2" failed (2: No such file or directory), client: 66.249.66.75, server: bot.itarashe.zone, request: "GET /assets/font/IranSans/IRANSans-Medium-web.woff2 HTTP/1.1", host: "oldflight.ir"
2018/09/27 01:09:02 [notice] 2811#2811: signal process started
2018/09/27 01:27:45 [notice] 2831#2831: signal process started
2018/09/27 01:42:01 [notice] 2876#2876: signal process started
2018/09/27 01:42:41 [notice] 2889#2889: signal process started
2018/09/27 01:43:54 [notice] 2902#2902: signal process started
2018/09/27 01:44:38 [notice] 2915#2915: signal process started
2018/09/27 01:50:06 [notice] 2936#2936: signal process started
Ok my problem solved, Nginx did what it needs to do, it calls socket but with /flask
and I didnt define #app.route('/flask')
Related
I have a sub-domain (foo.domain.com) that is maintained by my organization and in which I don't have control.
The organization configured that domain to point to a Route 53 service and from there I created a policy that sends the request to an ALB which then finally sends it to an EC2 running NGINX.
NGINX will be responsible for URL rewrites to many other services I have running in different EC2 instances.
What I want is, for example:
request is sent to foo.domain.com/service1
goes to Route53 then to an ALB and then to the EC2 running NGINX
in NGIX, I have the following config
...
location = /service1/
{
proxy_redirect off;
proxy_read_timeout 1m;
proxy_connect_timeout 1m;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_buffering off;
proxy_pass https://public_ip_of_service1_ec2_instance$request_uri;
}
This request goes to the EC2 instance running service1, which is another NGINX proxy running a node.js application (npm build kinda thing)
The NGINX service1 conf file is:
server {
listen 443 ssl;
listen [::]:443 ssl;
include snippets/self-signed.conf;
server_name public_ip_of_service1_ec2_instance;
root /app; #this is where the static files are hosted
location ~* \.html?$ {
expires -1;
add_header Pragma "no-cache";
add_header Cache-Control "no-store, must-revalidate";
}
location / {
add_header Content-Security-Policy "default-src 'self' 'unsafe-inline';";
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always;
add_header X-Frame-Options "SAMEORIGIN";
index index.html;
try_files $uri $uri/ /index.html;
# kill cache
# expires -1;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
If I hit the NGINX URL of service1, it works just fine, but the problem is when I call the NGINX proxy from step 3.
When I hit the URL foo.domain.com/service1 on the browser, I see this:
Basically, it says that foo.domain.com/js/chunk....js can't be found. This is correct since this file is being served in the EC2 that is running that node.js application (that is, it can be found at http://public_ip_of_service1_ec2_instance/js/chunk....js)
What is the configuration that I am missing in order to be able to keep the domain foo.domain.com/service1 for my users at all times and never to see the public_ip_of_service1_ec2_instance
Thank you
EDIT 1
The issue reported here seems to be exactly like mine: https://serverfault.com/questions/805836/reverse-proxy-application-and-its-static-files-with-nginx
I followed the suggestion there and as well as #anemyte suggestion but it is not working.
It seems like Proxy1 is trying to serve the static files that are hosted in Proxy2 as you can see here:
proxy | 2021/01/04 10:16:22 [error] 29#29: *4 open() "/etc/nginx/html/js/app.53272292.js" failed (2: No such file or directory), client: 172.19.0.1, server: apacbsa.com, request: "GET /js/app.53272292.js HTTP/1.1", host: "localhost", referrer: "http://localhost/auspost/"
proxy | ( - - ) 172.19.0.1 - - [04/Jan/2021:10:16:22 +0000] "GET /css/app.0988b263.css HTTP/1.1" 404 153 "http://localhost/auspost/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:80.0) Gecko/20100101 Firefox/80.0" "-"
proxy | ( - - ) 172.19.0.1 - - [04/Jan/2021:10:16:22 +0000] "GET /css/chunk-vendors.e78a06e5.css HTTP/1.1" 404 153 "http://localhost/auspost/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:80.0) Gecko/20100101 Firefox/80.0" "-"
proxy | 2021/01/04 10:16:22 [error] 29#29: *4 open() "/etc/nginx/html/css/app.0988b263.css" failed (2: No such file or directory), client: 172.19.0.1, server: apacbsa.com, request: "GET /css/app.0988b263.css HTTP/1.1", host: "localhost", referrer: "http://localhost/auspost/"
proxy | 2021/01/04 10:16:22 [error] 29#29: *6 open() "/etc/nginx/html/css/chunk-vendors.e78a06e5.css" failed (2: No such file or directory), client: 172.19.0.1, server: apacbsa.com, request: "GET /css/chunk-vendors.e78a06e5.css HTTP/1.1", host: "localhost", referrer: "http://localhost/auspost/"
proxy | 2021/01/04 10:16:23 [error] 29#29: *6 open() "/etc/nginx/html/js/chunk-vendors.7b27d7ff.js" failed (2: No such file or directory), client: 172.19.0.1, server: apacbsa.com, request: "GET /js/chunk-vendors.7b27d7ff.js HTTP/1.1", host: "localhost", referrer: "http://localhost/auspost/"
proxy | ( - - ) 172.19.0.1 - - [04/Jan/2021:10:16:23 +0000] "GET /js/chunk-vendors.7b27d7ff.js HTTP/1.1" 404 153 "http://localhost/auspost/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:80.0) Gecko/20100101 Firefox/80.0" "-"
proxy | 2021/01/04 10:16:23 [error] 29#29: *6 open() "/etc/nginx/html/js/app.53272292.js" failed (2: No such file or directory), client: 172.19.0.1, server: apacbsa.com, request: "GET /js/app.53272292.js HTTP/1.1", host: "localhost", referrer: "http://localhost/auspost/"
proxy | ( - - ) 172.19.0.1 - - [04/Jan/2021:10:16:23 +0000] "GET /js/app.53272292.js HTTP/1.1" 404 153 "http://localhost/auspost/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:80.0) Gecko/20100101 Firefox/80.0" "-"
My proxy 1 conf file looks like this now:
worker_processes 1;
events { worker_connections 1024; }
http {
log_format main '( $proxy_host $upstream_addr ) $remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
rewrite_log on;
access_log /var/log/nginx/access.log main;
server {
listen 80;
server_name apacbsa.com;
location /auspost/ {
# proxy_redirect off;
# proxy_read_timeout 1m;
# proxy_connect_timeout 1m;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# proxy_buffering off;
#proxy_set_header X-Real-IP $remote_addr;
# proxy_set_header X-Forwarded-Host $server_name;
proxy_pass https://192.168.1.113/;
}
}
}
EDIT2
Still no luck. This is what I am seeing in NGINX1 logs:
proxy | ( 192.168.1.113 192.168.1.113:443 ) 172.19.0.1 - - [05/Jan/2021:00:00:37 +0000] "GET /auspost/ HTTP/1.1" 200 2111 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:80.0) Gecko/20100101 Firefox/80.0" "-"
proxy | ( - - ) 172.19.0.1 - - [05/Jan/2021:00:00:37 +0000] "GET /css/chunk-vendors.e78a06e5.css HTTP/1.1" 404 153 "http://localhost/auspost/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:80.0) Gecko/20100101 Firefox/80.0" "-"
proxy | 2021/01/05 00:00:37 [error] 21#21: *9 open() "/etc/nginx/html/css/chunk-vendors.e78a06e5.css" failed (2: No such file or directory), client: 172.19.0.1, server: apacbsa.com, request: "GET /css/chunk-vendors.e78a06e5.css HTTP/1.1", host: "localhost", referrer: "http://localhost/auspost/"
proxy | ( - - ) 172.19.0.1 - - [05/Jan/2021:00:00:37 +0000] "GET /js/app.54337cb4.js HTTP/1.1" 404 153 "http://localhost/auspost/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:80.0) Gecko/20100101 Firefox/80.0" "-"
proxy | ( - - ) 172.19.0.1 - - [05/Jan/2021:00:00:37 +0000] "GET /css/app.0988b263.css HTTP/1.1" 404 153 "http://localhost/auspost/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:80.0) Gecko/20100101 Firefox/80.0" "-"
proxy | 2021/01/05 00:00:37 [error] 21#21: *12 open() "/etc/nginx/html/js/app.54337cb4.js" failed (2: No such file or directory), client: 172.19.0.1, server: apacbsa.com, request: "GET /js/app.54337cb4.js HTTP/1.1", host: "localhost", referrer: "http://localhost/auspost/"
proxy | 2021/01/05 00:00:37 [error] 21#21: *11 open() "/etc/nginx/html/css/app.0988b263.css" failed (2: No such file or directory), client: 172.19.0.1, server: apacbsa.com, request: "GET /css/app.0988b263.css HTTP/1.1", host: "localhost", referrer: "http://localhost/auspost/"
proxy | 2021/01/05 00:00:37 [error] 21#21: *13 open() "/etc/nginx/html/js/chunk-vendors.7b27d7ff.js" failed (2: No such file or directory), client: 172.19.0.1, server: apacbsa.com, request: "GET /js/chunk-vendors.7b27d7ff.js HTTP/1.1", host: "localhost", referrer: "http://localhost/auspost/"
proxy | ( - - ) 172.19.0.1 - - [05/Jan/2021:00:00:37 +0000] "GET /js/chunk-vendors.7b27d7ff.js HTTP/1.1" 404 153 "http://localhost/auspost/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:80.0) Gecko/20100101 Firefox/80.0" "-"
proxy | ( - - ) 172.19.0.1 - - [05/Jan/2021:00:00:38 +0000] "GET /css/app.0988b263.css HTTP/1.1" 404 153 "http://localhost/auspost/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:80.0) Gecko/20100101 Firefox/80.0" "-"
proxy | ( - - ) 172.19.0.1 - - [05/Jan/2021:00:00:38 +0000] "GET /css/chunk-vendors.e78a06e5.css HTTP/1.1" 404 153 "http://localhost/auspost/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:80.0) Gecko/20100101 Firefox/80.0" "-"
proxy | 2021/01/05 00:00:38 [error] 21#21: *12 open() "/etc/nginx/html/css/app.0988b263.css" failed (2: No such file or directory), client: 172.19.0.1, server: apacbsa.com, request: "GET /css/app.0988b263.css HTTP/1.1", host: "localhost", referrer: "http://localhost/auspost/"
proxy | 2021/01/05 00:00:38 [error] 21#21: *11 open() "/etc/nginx/html/css/chunk-vendors.e78a06e5.css" failed (2: No such file or directory), client: 172.19.0.1, server: apacbsa.com, request: "GET /css/chunk-vendors.e78a06e5.css HTTP/1.1", host: "localhost", referrer: "http://localhost/auspost/"
proxy | ( - - ) 172.19.0.1 - - [05/Jan/2021:00:00:39 +0000] "GET /js/chunk-vendors.7b27d7ff.js HTTP/1.1" 404 153 "http://localhost/auspost/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:80.0) Gecko/20100101 Firefox/80.0" "-"
proxy | 2021/01/05 00:00:39 [error] 21#21: *13 open() "/etc/nginx/html/js/chunk-vendors.7b27d7ff.js" failed (2: No such file or directory), client: 172.19.0.1, server: apacbsa.com, request: "GET /js/chunk-vendors.7b27d7ff.js HTTP/1.1", host: "localhost", referrer: "http://localhost/auspost/"
proxy | 2021/01/05 00:00:39 [error] 21#21: *11 open() "/etc/nginx/html/js/app.54337cb4.js" failed (2: No such file or directory), client: 172.19.0.1, server: apacbsa.com, request: "GET /js/app.54337cb4.js HTTP/1.1", host: "localhost", referrer: "http://localhost/auspost/"
proxy | ( - - ) 172.19.0.1 - - [05/Jan/2021:00:00:39 +0000] "GET /js/app.54337cb4.js HTTP/1.1" 404 153 "http://localhost/auspost/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:80.0) Gecko/20100101 Firefox/80.0" "-"
And this is what I see in the NGINX2 (serving static files) logs (just 1 line):
frontend | 172.21.0.1 - - [05/Jan/2021:11:04:17 +1100] "GET / HTTP/1.0" 200 2111 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:80.0) Gecko/20100101 Firefox/80.0" "172.19.0.1"
This is the full nginx conf file for NGINX2:
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;
keepalive_timeout 10m;
proxy_connect_timeout 600s;
proxy_send_timeout 600s;
proxy_read_timeout 600s;
fastcgi_send_timeout 600s;
fastcgi_read_timeout 600s;
resolver_timeout 600s;
# for DDOS protection - 3 requests per second
limit_req_zone $binary_remote_addr zone=one:10m rate=3r/s;
# limiting the number of connections one client can make
limit_conn_zone $binary_remote_addr zone=addr:10m;
server {
listen 80;
listen [::]:80;
server_name apacbsa.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl;
listen [::]:443 ssl;
include snippets/self-signed.conf;
server_name apacbsa.com;
root /app;
location ~* \.html?$ {
expires -1;
add_header Pragma "no-cache";
add_header Cache-Control "no-store, must-revalidate";
}
location /auspost/ {
add_header Content-Security-Policy "default-src 'self' 'unsafe-inline';";
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always;
add_header X-Frame-Options "SAMEORIGIN";
index index.html;
try_files $uri $uri/ /index.html;
# kill cache
# expires -1;
}
location /api {
# limiting the number of api calls
limit_req zone=one burst=2 nodelay;
# only one connection per client to the api
limit_conn addr 1;
proxy_pass https://backend:5001/api;
proxy_redirect off;
proxy_connect_timeout 1m;
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_cache_bypass $http_upgrade;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
}
Everything is running in docker containers, but that shouldn't be the problem I don't think.
So I issue the request from my browser in my Mac laptop and in that laptop I am running the NGINX1 proxy. That then forwards to my Windows machine running NGINX2 static files.
When you declare a location like that:
location = /service1/
It means that you want exact URL match. So it will only work for foo.domain.com/service1/ while foo.domain.com/service1/something won't match this location. Looking at the URL of your request (/js/chunk) this isn't what you want, so remove = from the location:
location /service1/
Next is the server_name. Your first proxy passes Host header which NGINX uses to determine which vhost configuration to use. The Host header value should be foo.domain.com but your server_name on the second NGINX is public_ip_of_service1_ec2_instance. It doesn't matter if the vhost is a default one but I don't see that in your configuration.
You can add foo.domain.com after public_ip_of_service1_ec2_instance or just replace one with the other. What's best in this case you should decide yourself and if you wish to learn more about server names I recommend you reading these great articles: How nginx processes a request and Server names
UPD: About missing static files.
You need to change base URL or base path of your service1 application from / to /service1/. This is not related to NGINX, unless your application is made of just static files.
Why did that happen? Well you've told first NGINX that you want all requests with URL starting with /service1/ to be forwarded to service1. When a client hits service1, the page refers some static, /js/chunk-vendors.7b27d7ff.js for example. Client's browser makes an additional request to the first NGINX asking to provide /js/chunk-vendors.7b27d7ff.js. Since the URL does not begin with /service1/ NGINX does not forward the request to /service1/ and it uses another piece of config for this request (/ most likely).
If you change all absolute URLs at service1 to begin with /service1/ the problem should go. A dangerous alternative to that would be removing first slash from absolute links. This way URLs will be relative to current location and not website root. Think twice before going second option.
I have done some testing lately and here's what I found out:
In your nginx proxy config, remove the line:
proxy_set_header Host $http_host;
Which will result in your final configuration nginx file to be:
location = /
{
proxy_redirect off;
proxy_read_timeout 1m;
proxy_connect_timeout 1m;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_buffering off;
proxy_pass https://public_ip_of_service1_ec2_instance;
}
You could configure something like this in the first nginx server
server {
listen 80;
listen [::]:80;
listen 443 http2 ssl;
listen [::]:443 http2 ssl;
server_name domain1;
if ($request_method ~* OPTIONS|GET|HEAD) {
return 301 https://domain2$request_uri;
}
location ~* api {
proxy_pass https://domain2$request_uri;
}
}
I want to do proxy_pass for
https://atmvpn.appdomain.cloud/sft-ui/sft/api/orgs/v1/org in such a way that should be
https://dev.apnat.net/sft/api/orgs/v1/orgso while proxy_pass we need to remove sft-ui so I add below location in nginx.conf file
`location /sft-ui/sft/api {
access_log off;
rewrite ^/sft-ui/(.*) /$1 break;
proxy_pass <%= ENV["AMS_DOMAIN"] %>;
}`
I have set AMS_DOMAIN as environment variable. But when I hit https://atmvpn.appdomain.cloud/sft-ui/sft/api/orgs/v1/org in browser I get error "502 Bad Gateway".
in Logs of openshift pod I can see:
2020/06/05 07:06:46 [error] 11#11: *1 SSL_do_handshake() failed (SSL: error:14094410:SSL routines:ssl3_read_bytes:sslv3 alert handshake failure:SSL alert number 40) while SSL handshaking to upstream, client: 172.30.96.141, server: , request: "GET /sft-ui/sft/api/orgs/v1/org HTTP/1.1", upstream: "https://104.18.12.180:443/sft/api/orgs/v1/org", host: "atmvpn.appdomain.cloud"
2020/06/05 07:06:46 [warn] 11#11: *1 upstream server temporarily disabled while SSL handshaking to upstream, client: 172.30.96.141, server: , request: "GET /sft-ui/sft/api/orgs/v1/org HTTP/1.1", upstream: "https://104.18.12.180:443/sft/api/orgs/v1/org", host: "atmvpn.appdomain.cloud"
Just adding proxy_ssl_server_name on; its resolved
location /sft-ui/sft/api {
access_log off;
rewrite ^/sft-ui/(.*) /$1 break;
proxy_pass <%= ENV["AMS_DOMAIN"] %>;
#By setting to "on" can proxy to upstream hosts using SNI
proxy_ssl_server_name on;
}
I am trying to run Akka service using nginx. Here is my default.conf:
upstream hello-akka{
server localhost:9000;
}
server {
listen 9000;
location /* {
root /usr/share/nginx/html;
index index.html index.htm;
}
location /akka {
proxy_pass http://hello-akka;
}
location /assets {
root /var/www;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
Default nginx page works just fine but when I redirect to /akka I get 500 internal server error. Here is my nginx log file:
2017/12/05 10:58:17 [crit] 11077#11077: *1014 open() "/usr/share/nginx/html/50x.html" failed (24: Too many open files), client: 127.0.0.1, server: , request: "GET /akka HTTP/1.0", upstream: "http://127.0.0.1:9000/akka", host: "hello-akka"
I have changed /etc/security/limits.con file to increase the number of connections from 1024 to 16384. However, after that I keep getting another error:
host: "hello-akka"
2017/12/05 11:40:42 [error] 15916#15916: *37494 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 127.0.0.1, server: , request: "GET /akka HTTP/1.0", upstream: "http://127.0.0.1:9000/akka"
So what is wrong with my configurations and how should I change them to run /akka page normally?
UPDATE: I have changed server localhost:9000 to server localhost:8080 in upstream hello-akka. However, when I redirect to localhost:9000/akka I get An error occurred page.
Error logs shows this error:
*1 connect() failed (111: Connection refused) while connecting to upstream, client: 127.0.0.1, server: , request: "GET /akka HTTP/1.1", upstream: "http://127.0.0.1:8080/akka", host: "localhost:9000"
Nginx 403 error,so how can i fix this problem?
When i access the main.css from chrome browser,it response me 403 error.
➜ ~ tail -fn4 /var/log/nginx/error.log
2016/04/23 08:16:51 [error] 10488#0: *1 open() "/data/apache-tomcat-8.0.33/webapps/ROOT/static/css/main.css" failed (13: Permission denied), client: x.x.x.x, server: www.xx.com, request: "GET /static/css/main.css HTTP/1.1", host: "xx.com"
2016/04/23 08:16:53 [error] 10488#0: *1 open() "/data/apache-tomcat-8.0.33/webapps/ROOT/static/css/main.css" failed (13: Permission denied), client: x.x.x.x, server: www.xx.com, request: "GET /static/css/main.css HTTP/1.1", host: "xx.com"
2016/04/23 08:21:48 [error] 10488#0: *4 open() "/data/apache-tomcat-8.0.33/webapps/ROOT/static/css/main.css" failed (13: Permission denied), client: x.x.x.x, server: www.xx.com, request: "GET /static/css/main.css HTTP/1.1", host: "xx.com"
2016/04/23 08:24:49 [error] 10488#0: *5 open() "/data/apache-tomcat-8.0.33/webapps/ROOT/static/css/main.css" failed (13: Permission denied), client: x.x.x.x, server: www.xx.com, request: "GET /static/css/main.css HTTP/1.1", host: "xx.com"
namei tool,all parent directory have 755,and the main.css have 644.
➜ ~ namei -l /data/apache-tomcat-8.0.33/webapps/ROOT/static/css/main.css
f: /data/apache-tomcat-8.0.33/webapps/ROOT/static/css/main.css
drwxr-xr-x root root /
drwxr-xr-x root root data
drwxr-xr-x root root apache-tomcat-8.0.33
drwxr-xr-x root root webapps
drwxr-xr-x root root ROOT
drwxr-xr-x root root static
drwxr-xr-x root root css
-rw-r--r-- root root main.css
start nginx's user is root:
➜ ~ ps aux | grep "nginx: worker process" | awk '{print $1}'
root
nginx conf:
upstream tomcat {
server 127.0.0.1:8887;
}
server {
listen 80;
server_name www.xx.com xx.com;
charset utf-8;
access_log /var/log/nginx/tomcat.access.log main;
location / {
proxy_pass http://tomcat;
proxy_redirect off;
client_max_body_size 500M;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
}
location ~ .*\.(gif|jpg|jpeg|bmp|png|ico|txt|js|css)$
{
root /data/apache-tomcat-8.0.33/webapps/ROOT;
expires 7d;
}
location ~ ^/(WEB-INF)/ {
deny all;
}
}
It's quite possible that you are hosting on a machine that has selinux enforced.
what does sestatus give you?
The site runs with nginx and an uwsgi (flask app) and shellinabox terminal.
After every 20 or 30 minutes, the shellinabox terminal is not getting loaded and the nginx log shows this -
2012/05/26 14:20:27 [error] 4547#0: *117 readv() failed (104: Connection reset by peer) while reading upstream, client: 192.168.122.128, server: _, request: "POST /login/ HTTP/1.1", upstream: "uwsgi://127.0.0.1:1973", host: "www.MYwebapp.org", referrer: "http://www.MYwebapp.org/login/"
2012/05/26 14:20:31 [crit] 4547#0: *105 mkdir() "/var/lib/nginx/tmp/proxy/3/00" failed (13: Permission denied) while reading upstream, client: 192.168.122.128, server: _, request: "GET /terminal/proxy/ShellInABox.js HTTP/1.1", upstream: "http://127.0.0.1:4200/ShellInABox.js", host: "www.MYwebapp.org", referrer: "http://www.MYwebapp.org/terminal/proxy/index/"
2012/05/26 14:21:06 [error] 4547#0: *103 upstream timed out (110: Connection timed out) while reading response header from upstream
, client: 192.168.122.128, server: _, request: "POST /terminal/proxy/? HTTP/1.1", upstream: "http://127.0.0.1:4200/", host: "www.MYwebapp.org", referrer: "http://www.MYwebapp.org/terminal/proxy/index/"
2012/05/26 14:21:06 [error] 4547#0: *103 open() "/var/www/MYwebapp/templates/50x.html" failed (13: Permission denied), client: 192.168.122.128, server: _, request: "POST /terminal/proxy/? HTTP/1.1", upstream: "http://127.0.0.1:4200/", host: "www.MYwebapp.org", referrer: "http://www.MYwebapp.org/terminal/proxy/index/"
2012/05/26 14:22:31 [error] 4547#0: *136 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 192.168.122.128, server: _, request: "GET /terminal/proxy/index/ HTTP/1.1", upstream: "http://127.0.0.1:4200/index/", host: "www.MYwebapp.org", referrer: "http://www.MYwebapp.org/terminal/"
2012/05/26 14:22:31 [error] 4547#0: *136 open() "/var/www/MYwebapp/templates/50x.html" failed (13: Permission denied), client: 192.168.122.128, server: _, request: "GET /terminal/proxy/index/ HTTP/1.1", upstream: "http://127.0.0.1:4200/index/", host: "www.MYwebapp.org", referrer: "http://www.MYwebapp.org/terminal/"
I tried to put sometime-out values ... nothing helped so far.
As I'm pretty much new to nginx/uwsgi/shellinabox, I'm currently stuck with this.
Here is my nginx.conf file -
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/MYwebapp_access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
#
# The default server
#
server {
listen 80;
server_name _;
#charset koi8-r;
#access_log logs/host.access.log main;
location /terminal/proxy {
rewrite ^/terminal/proxy/(.*)$ /$1 break;
proxy_pass http://localhost:4200/index;
proxy_set_header X-Real-IP $remote_addr;
#proxy_read_timeout 3000;
uwsgi_connect_timeout 6000;
uwsgi_read_timeout 6000;
uwsgi_send_timeout 6000;
}
location / { try_files $uri #MYwebapp; }
location #MYwebapp {
include uwsgi_params;
uwsgi_pass localhost:1973;
uwsgi_connect_timeout 6000;
uwsgi_read_timeout 6000;
uwsgi_send_timeout 6000;
}
error_page 404 /404.html;
location = /404.html {
root /var/www/MYwebapp/templates;
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/MYwebapp/templates;
}
}
# Load config files from the /etc/nginx/conf.d directory
include /etc/nginx/conf.d/*.conf;
2012/05/26 14:21:06 [error] 4547#0: *103 upstream timed out (110: Connection timed out) while reading response header from upstream
, client: 192.168.122.128, server: _, request: "POST /terminal/proxy/? HTTP/1.1", upstream: "http://127.0.0.1:4200/", host: "www.MYwebapp.org", referrer: "http://www.MYwebapp.org/terminal/proxy/index/"
2012/05/26 14:21:06 [error] 4547#0: *103 open() "/var/www/MYwebapp/templates/50x.html" failed (13: Permission denied), client: 192.168.122.128, server: _, request: "POST /terminal/proxy/? HTTP/1.1", upstream: "http://127.0.0.1:4200/", host: "www.MYwebapp.org", referrer: "http://www.MYwebapp.org/terminal/proxy/index/"
2012/05/26 14:22:31 [error] 4547#0: *136 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 192.168.122.128, server: _, request: "GET /terminal/proxy/index/ HTTP/1.1", upstream: "http://127.0.0.1:4200/index/", host: "www.MYwebapp.org", referrer: "http://www.MYwebapp.org/terminal/"
2012/05/26 14:22:31 [error] 4547#0: *136 open() "/var/www/MYwebapp/templates/50x.html" failed (13: Permission denied), client: 192.168.122.128, server: _, request: "GET /terminal/proxy/index/ HTTP/1.1", upstream: "http://127.0.0.1:4200/index/", host: "www.MYwebapp.org", referrer: "http://www.MYwebapp.org/terminal/"