When on a higher port, say 8000, my static files are loaded fine. When I run the server on port 80 (using sudo), I get 403 errors. Any idea why this would be?
My only thought is that its something to do with running as root, the file permissions are all normal, even going -777- doesn't change the error.
# the upstream component nginx needs to connect to
events {
worker_connections 1024;
}
http{
upstream django {
server 127.0.0.1:8001;
}
# configuration of the server
server {
# the port your site will be served on
listen 80;
root ~/my/path/;
# the domain name it will serve for
server_name 127.0.0.1;
charset utf-8;
# max upload size
client_max_body_size 75M; # adjust to taste
# Django media
location /media {
alias _; # your Django project's media files - amend as required
}
location /static/ {
autoindex on;
root /my/path/static/;
}
location ~ \.css {
root /my/path/static/;
}
location ~ \.js {
root /my/path/static/;
}
# Finally, send all non-media requests to the Django server.
location / {
uwsgi_pass django;
include ../uwsgi_params;
}
}
}
You need to add this context to your content directory:
chcon -R -t httpd_sys_content_t /my/path/static
Or you need to disable Selinux.
Edit /etc/sysconfig/selinux file to disable selinux permanently.
setenforce 0 to disable selinux on-the-fly.
Related
I'm trying to configure Nginx location for hours, not sure what I'm doing wrong:
server {
listen 80;
server_name test.myserver.com;
location = / {
root /www/;
}
location / {
proxy_pass http://192.168.0.170;
}
}
Nginx is running on OpenWRT router, inside /www/ there is only a index.html file. All other addresses should be proxied to an Arduino in 192.168.0.170.
I understand "location = /" rule should precede "location /". I'm avoiding creating a rule for any other address than "/", like /a, /b, /c, and go on.
With this code, I get a 404 from "/", as there is no index.html in 192.168.0.170. If I remove "location / { proxy_pass ...}", I could get index.html result from "/" address.
EDIT:
-Including a return 302 /blah; inside "location = /" block works fine, so the rule is being applied.
For anyone that drop here, the solution I've found:
server {
listen 80;
server_name test.myserver.com;
root /www/;
location = / { }
location /index.html { }
location / {
proxy_pass http://192.168.0.170;
}
}
Ugly, but it works. Maybe OpenWRT implementation (version 1.12.2) isn't as reliable a full distribution (current in 1.19.1 version).
In my example, just copied you configuration and did a little tweak, to match with a current configuration I use in my server.
Changed the listen to a default_server
Added root to the server block.
Added index index.html index.htm; line.
You can try the following configuration:
server {
listen 80 default_server;
root /www;
index index.html index.htm;
server_name test.myserver.com;
location / {
proxy_pass http://192.168.0.170;
}
}
After change your configuration test your server block file with command:
sudo nginx -t
If everything is okay, restart the nginx instance:
sudo nginx -s reload
After restart with success if you are trying access via browser, try using incognito mode in a new browser instance. (just for cache clean)
I have my flask application deployed on Nginx over my VM.
Everything is deployed Ok and I can request my apis on http://my.ip.number (I have a public IP)
But when I run Ngrok (I need https and I don't have a domain name to generate a SSL certificate), the URL https//number.ngrok.io shows me the Nginx home page (Welcome to Nginx) instead my webapp.
Why is this happening?
P.D: When I run "curl localhost" I get the Nginx Welcome Page but when I exec "curl -4 localhost" I get my webapp home page
etc/nginx/site-available/myproject
server {
listen 80;
server_name 0.0.0.0;
location / {
include proxy_params;
proxy_pass http://unix:/home/datascience/chatbot-cima/chatbot.sock;
}
}
server {
listen 80;
server_name 127.0.0.1;
location / {
proxy_pass http://unix:/home/datascience/chatbot-cima/chatbot.sock;
}
}
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://unix:/home/datascience/chatbot-cima/chatbot.sock;
}
}
server {
listen 80;
server_name public.ip;
location / {
proxy_pass http://unix:/home/datascience/chatbot-cima/chatbot.sock;
}
}
Any request coming in from ngrok, has the Host header set to the ngrok URL. The behaviour of nginx would be to try and match one of the server blocks in your configuration above, and default to the first one if no server_name matches the Host header.
However, I'm guessing there's another configuration file at /etc/nginx/conf.d/default.conf or /etc/nginx/sites-enabled/0-default which has a listen directive with default_server set. That will be catching these requests and serving the "Welcome to nginx!" page.
I suggest you look for that file, and remove it which should solve the issue.
However you could also simplify the above configuration and simply have:
server {
listen 80;
server_name localhost;
location / {
include proxy_params;
proxy_pass http://unix:/home/datascience/chatbot-cima/chatbot.sock;
}
}
Provided there's not another server block hiding somewhere else in the configuration with a directive like listen 80 default_server; then this should catch all requests.
For more info see: How nginx processes a request
Need help with my web server configuration. I'm using Python Django, Gunicorn, Nginx. DNS Lookup tool shows correct IP. When I go to my domain name it returns Bad Request (400)
#GODADDY RECORDS:
Type Name Value TTL Actions
1. a # 11.222.33.444 600 seconds
2. a www 11.222.33.444 600 seconds
#My SETTINGS.PY FILE:
ALLOWED_HOSTS = ['11.222.33.444']
#NGNIX SETTINGS:
server {
listen 80;
server_name 11.222.33.444 domainname.com www.domainname.com;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/ubuntu/Portfolio;
}
location / {
include proxy_params;
proxy_pass http://unix:/home/ubuntu/Portfolio/main.sock;
}
}
I'm completely new to nginx. I've installed nginx on windows pc.
What I want to do is server a list of files in D:\ on localhost:8082/list.
If I use the following conf:
server {
listen 8082;
location / {
root D:/;
autoindex on;
}
}
I can correctly see what i want on localhost:8082. But if I change it to:
server {
listen 8082;
location /list {
root D:/;
autoindex on;
}
}
The page localhost:8082/list gives a 404 error.
What you need is alias instead of root.
server {
listen 8082;
location /list {
alias D:/; ##### use alias, not root
autoindex on;
}
}
See Nginx -- static file serving confusion with root & alias
I'm new to using nginx, well, new to using anything that's not cpanel... I'm having problems getting domains to work using nginx when you include www. in the url.
www.mydomain.com > not work 404
mydomain.com > works
I'm not sure if I have made mistake with named config files, or the server config for nginx. I'm kinda learning in a hurry and I'm not going to be surprised if I made some error with basic configuration. I run latest nginx & php-fpm, apart from my domain issue it works.
I'm (trying?) to run subdomains, they work, but using www. will result in a 404. I use nameservers etc from my main .org server domain.
I'm going to post all that is relevant below in the hope someone here can spot the errors I am making/or made.
etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6
184.xxx.xxx.146 server.servername.org servername.org
named.conf
...
view "localhost_resolver" {
/* This view sets up named to be a localhost resolver ( caching only nameserver ).
* If all you want is a caching-only nameserver, then you need only define this view:
*/
# match-clients { 127.0.0.0/24; };
# match-destinations { localhost; };
match-clients { any; };
match-destinations { any; };
recursion no;
zone "servername.org" {
type master;
file "/var/named/servername.org.db";
};
// optional - we act as the slave (secondary) for the delegated domain
zone "mydomain.com" IN {
type slave;
file "/var/named/mydomain.com.db";
masters {10.10.0.24;};
};
allow-notify { 184.xxx.xxx.146; };
};
mydomain.com.db
$TTL 86400
mydomain.com. IN SOA ns1.servername.org. server.servername.org. (
2002012013; Serial
1H ; Refresh (change 1H to 6H in 3 days or so)
1800 ; Retry (change to 1H in 3 days)
2W ; Expire
1D ); Minimum
mydomain.com. IN NS ns1.servername.org.
mydomain.com. IN NS ns2.servername.org.
ns1.servername.org. IN A 184.xxx.xxx.147
ns2.servername.org. IN A 184.xxx.xxx.148
mail.servername.org. IN A 184.xxx.xxx.146
mydomain.com. IN A 184.xxx.xxx.146
mydomain.com. IN MX 0 mail.servername.org.
# A 184.xxx.xxx.146
www A 184.xxx.xxx.146
nginx.conf uses include /etc/nginx/sites-enabled/*;
and the nginx "mydomain.com" config
server {
server_name www.mydomain.com;
rewrite ^(.*) http://mydomain.com$1 permanent;
}
server {
listen 80;
server_name mydomain.com www.mydomain.com;
# access_log /srv/www/mydomain.com/logs/access.log;
error_log /srv/www/mydomain.com/logs/error.log;
root /srv/www/mydomain.com/public_html;
set $noadmin 1;
location / {
try_files $uri $uri/ /index.php?$args;
index index.html index.htm index.php;
}
# Add trailing slash to */wp-admin requests.
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
location ~ \.flv$ {
flv;
root /srv/www/mydomain.com/public_html;
}
location ~ \.mp4$ {
root /srv/www/mydomain.com/public_html;
mp4;
}
# use fastcgi for all php files
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /srv/www/mydomain.com/public_html$fastcgi_script_name;
include fastcgi_params;
}
# deny access to apache .htaccess files
location ~ /\.ht
{
deny all;
}
}
I can access subdomains, so my horrible attempt at this seems to be kind of working, I am stuck on why www.mydomain.com will not connect, while http://mydomain.com will. I am reading/learning more as I go along, I do not want to make changes until I have understanding of what the changes do. I may end up breaking more then the URLs.
You are rewriting www.domain.com on first few lines of nginx.conf. If i'm not wrong, rewriting and redirecting are different things. Try this on first server block;
server {
server_name www.mydomain.com;
return 301 http://mydomain.com$request_uri;
}
and change
server_name mydomain.com www.mydomain.com
to
server_name mydomain.com
in second server block.
my solution and it works for me
server {
listen 80;
server_name yourdomainname.com www.yourdomainname.com;
return 301 https://$server_name$request_uri;
}
write the previous code inside that file --> yourdomainname.conf
nginx