My error
Unable to connect
Firefox can’t establish a connection to the server at 127.0.0.1:8888.
ls -l /etc/fdfs/
total 84
-rw-r--r-- 1 root root 1469 六月 14 10:10 client.conf
-rw-r--r-- 1 root root 1461 六月 14 09:44 client.conf.sample
-rw-r--r-- 1 root root 955 六月 14 14:31 http.conf
-rw-r--r-- 1 root root 31172 六月 14 14:31 mime.types
-rw-r--r-- 1 root root 3725 六月 14 14:22 mod_fastdfs.conf
-rw-r--r-- 1 root root 7938 六月 14 10:02 storage.conf
-rw-r--r-- 1 root root 7927 六月 14 09:44 storage.conf.sample
-rw-r--r-- 1 root root 105 六月 14 09:44 storage_ids.conf.sample
-rw-r--r-- 1 root root 7394 六月 14 10:25 tracker.conf
-rw-r--r-- 1 root root 7389 六月 14 09:44 tracker.conf.sample
my server
ps aux |grep nginx
root 29867 0.0 0.0 38152 616 ? Ss 14:41 0:00 nginx: master process ./nginx
coco 30010 0.0 0.0 21532 1084 pts/2 S+ 14:55 0:00 grep --color=auto nginx
/usr/local/nginx/conf
http {
include 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 logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 8888;
server_name localhost;
location ~/group[0-9]/ {
ngx_fastdfs_module;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
I am trying to view picture that I just upload .
Command like this
fdfs_upload_file /etc/fdfs/client.conf /home/coco/Pictures/coco.jpg
group1/M00/00/00/wKgTgF7lxkyAGO0-AAAiaSlNP3Q922.jpg
I double check my tracker.conf and I find I forget change bath_path
It should be
base_path=/home/coco/fastdfs/tracker/
After change my server process like this
root 31082 0.0 0.2 141252 6804 ? Ss 15:28 0:00 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
www-data 31546 0.0 0.2 143924 6464 ? S 15:36 0:00 nginx: worker process
www-data 31547 0.0 0.2 143924 6464 ? S 15:36 0:00 nginx: worker process
root 31678 0.0 0.0 38156 616 ? Ss 15:45 0:00 nginx: master process ./nginx
nobody 31679 0.0 0.1 43096 4184 ? S 15:45 0:00 nginx: worker process
root 31712 0.0 0.0 21532 1056 pts/3 S+ 15:47 0:00 grep --color=auto nginx
enter image description here
It's work
Related
I am trying to deploy my Django project through Ubuntu Apache2 but I am getting Forbidden You don't have permission to access this resource error. I cannot seem to find the solution
Error:
Server Error
My config file
`Alias /static /home/rapicare/rapid-care-website/rapidCare/static
<Directory /home/rapicare/rapid-care-website/rapidCare/static>
Require all granted
Alias /media /home/rapicare/rapid-care-website/rapidCare/media
<Directory /home/rapicare/rapid-care-website/rapidCare/media>
Require all granted
</Directory>
<Directory /home/rapicare/rapid-care-website/rapidCare/rapidCare>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess django_app python-path=/home/rapicare/rapid-care-website/rapidCare python-home=/home/rapicare/rapid-care-website/venv
WSGIProcessGroup django_app
WSGIScriptAlias / /home/rapicare/rapid-care-website/rapidCare/rapidCare/wsgi.py`
My Directoy permissions
rapidcare#rapidcare:~$ ls rapid-care-website -la total 28 drwxrwxr-x 5 rapidcare www-data 4096 Feb 5 09:11 . drwxr-x--x 5 rapidcare rapidcare 4096 Feb 5 16:48 .. -rw-rw-r-- 1 rapidcare rapidcare 0 Feb 4 11:52 .editorconfig drwxrwxr-x 8 rapidcare rapidcare 4096 Feb 5 09:14 .git -rw-rw-r-- 1 rapidcare rapidcare 651 Feb 4 11:52 .gitignore drwxrwxr-x 7 rapidcare www-data 4096 Feb 4 22:12 rapidCare -rw-rw-r-- 1 rapidcare rapidcare 249 Feb 4 11:52 requirements.txt drwxrwxr-x 5 rapidcare www-data 4096 Feb 4 22:12 venv
rapidcare#rapidcare:~/rapid-care-website$ ls -la rapidCare/ total 388 drwxrwxr-x 7 rapidcare www-data 4096 Feb 4 22:12 . drwxrwxr-x 5 rapidcare www-data 4096 Feb 5 09:11 .. -rw-rw-r-- 1 rapidcare www-data 360448 Feb 4 12:55 db.sqlite3 -rwxrwxr-x 1 rapidcare rapidcare 665 Feb 4 11:52 manage.py drwxrwxr-x 3 rapidcare www-data 4096 Feb 4 11:52 media drwxrwxr-x 3 rapidcare rapidcare 4096 Feb 5 16:42 rapidCare drwxrwxr-x 7 rapidcare rapidcare 4096 Feb 4 22:12 services drwxrwxr-x 8 rapidcare rapidcare 4096 Feb 4 22:12 static drwxrwxr-x 6 rapidcare rapidcare 4096 Feb 4 22:12 userAuth]]
My Apache Status
`● apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; preset: enabled)
Active: active (running) since Sun 2023-02-05 17:08:43 UTC; 8min ago
Docs: https://httpd.apache.org/docs/2.4/
Process: 113195 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
Main PID: 113199 (apache2)
Tasks: 56 (limit: 1116)
Memory: 12.9M
CPU: 4.412s
CGroup: /system.slice/apache2.service
├─113199 /usr/sbin/apache2 -k start
├─113201 /usr/sbin/apache2 -k start
└─113202 /usr/sbin/apache2 -k start
Feb 05 17:08:43 rapidcare systemd[1]: Stopped The Apache HTTP Server.
Feb 05 17:08:43 rapidcare systemd[1]: apache2.service: Consumed 12.560s CPU time.
Feb 05 17:08:43 rapidcare systemd[1]: Starting The Apache HTTP Server...
Feb 05 17:08:43 rapidcare apachectl[113198]: AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 139.59.20.219. Set the 'ServerName' directive globally to suppress this message
Feb 05 17:08:43 rapidcare systemd[1]: Started The Apache HTTP Server.`
I am following https://www.youtube.com/watch?v=Sa_kQheCnds&list=PL-osiE80TeTtoQCKZ03TU5fNfx2UY6U4p&index=13&ab_channel=CoreySchafer tutorial. I have tried many other settings but it is still giving error. Someone suggested binding to ports under 1024 requires superuser privileges but I don't know how that works.
I followed this tutorial : http://michal.karzynski.pl/blog/2013/06/09/django-nginx-gunicorn-virtualenv-supervisor/
My directory structure is quite the same:
-rw-r--r-- 1 django webapps 0 Nov 30 15:58 access.log
drwxr-xr-x 3 django webapps 4096 Nov 30 17:27 bin
-rw-r--r-- 1 django webapps 6450 Nov 30 15:58 error.log
drwxr-xr-x 2 django webapps 4096 Nov 30 15:58 gunicorn
drwxr-xr-x 2 django webapps 4096 Nov 30 16:10 include
drwxr-xr-x 3 django webapps 4096 Nov 30 16:10 lib
lrwxrwxrwx 1 django webapps 3 Nov 30 16:10 lib64 -> lib
drwxr-xr-x 2 django webapps 4096 Nov 30 17:12 logs
drwxr-xr-x 5 django webapps 4096 Nov 30 13:36 narcisse
-rw-r--r-- 1 django webapps 59 Nov 30 16:11 pip-selfcheck.json
-rw-r--r-- 1 django webapps 75 Nov 30 16:10 pyvenv.cfg
-rw-r--r-- 1 django webapps 85 Nov 30 15:50 README.md
drwxrwxrwx 2 django webapps 4096 Nov 30 17:51 run
I have a /etc/supervisor/conf.d/filename that looks like this:
[program:site]
command = /var/www/site/bin/gunicorn_start -user=django
user = django
stdout_logfile = /var/www/site/logs/gunicorn_supervisor.log
redirect_stderr = true
My gunicorn_start is located inside /var/www/site/bin ()and looks like this:
NAME="api"
DJANGODIR=/var/www/site/site
SOCKFILE=/var/www/site/run/gunicorn.sock
USER=django
GROUP=webapps
NUM_WORKERS=3
DJANGO_SETTINGS_MODULE=api.settings
DJANGO_WSGI_MODULE=api.wsgi
echo "Starting $NAME as `whoami`"
# Activate the virtual environment
cd $DJANGODIR
source ../bin/activate
export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE
export PYTHONPATH=$DJANGODIR:$PYTHONPATH
# Create the run directory if it doesn't exist
RUNDIR=$(dirname $SOCKFILE)
test -d $RUNDIR || mkdir -p $RUNDIR
# Start your Django Unicorn
exec ../bin/gunicorn ${DJANGO_WSGI_MODULE}:application \
--name $NAME \
--workers $NUM_WORKERS \
--user=$USER --group=$GROUP \
--bind=unix:$SOCKFILE \
--log-level=debug \
--log-file=-
And finally the nginx conf file:
upstream your-gunicorn {
server unix:/var/www/site/run/gunicorn.sock fail_timeout=0;
}
server {
listen 80 default;
client_max_body_size 4G;
server_name <ip_address>;
keepalive_timeout 70;
access_log /var/log/nginx/site.access_log;
error_log /var/log/nginx/site.error_log;
root /var/www/site/;
location /static/ {
autoindex on;
alias /var/www/site/site/static/;
expires 1M;
access_log off;
add_header Cache-Control "public";
proxy_ignore_headers "Set-Cookie";
}
location #proxy_to_app {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://127.0.0.1;
}
location / {
try_files $uri #proxy_to_app;
}
}
I have the feeling I have tried every keyboard combinations. Cannot find what is wrong.
I keep getting this Operation Not permitted error inside gunicorn logs right after it starts.
Here is the full output:
[2018-11-30 17:49:28 +0000] [13849] [INFO] Starting gunicorn 19.9.0
[2018-11-30 17:49:28 +0000] [13849] [DEBUG] Arbiter booted
[2018-11-30 17:49:28 +0000] [13849] [INFO] Listening at: unix:/var/www/site/run/gunicorn.sock (13849)
[2018-11-30 17:49:28 +0000] [13849] [INFO] Using worker: sync
[2018-11-30 17:49:28 +0000] [13923] [INFO] Booting worker with pid: 13923
[2018-11-30 17:49:28 +0000] [13923] [ERROR] Exception in worker process
Traceback (most recent call last):
File "/var/www/site/lib/python3.6/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
worker.init_process()
File "/var/www/site/lib/python3.6/site-packages/gunicorn/workers/base.py", line 93, in init_process
initgroups=self.cfg.initgroups)
File "/var/www/site/lib/python3.6/site-packages/gunicorn/util.py", line 165, in set_owner_process
os.setgid(gid)
PermissionError: [Errno 1] Operation not permitted
Thank you for your help.
Julien
So, with the help of Haken Lid, I managed to fix my architecture.
Here is what I did:
Fixed nginx configuration file
upstream your-gunicorn {
server unix:/var/www/site/run/gunicorn.sock fail_timeout=0;
}
Changed to:
upstream gunicorn_upstream {
server unix:/var/www/site/run/gunicorn.sock fail_timeout=0;
}
And:
proxy_pass http://127.0.0.1;
Changed to:
proxy_pass http://gunicorn_upstream;
Fixed gunistart_start file
Last line changed from:
exec ../bin/gunicorn ${DJANGO_WSGI_MODULE}:application \
--name $NAME \
--workers $NUM_WORKERS \
--user=$USER --group=$GROUP \
--bind=unix:$SOCKFILE \
--log-level=debug \
--log-file=-
To:
exec ../bin/gunicorn ${DJANGO_WSGI_MODULE}:application \
--name $NAME \
--workers $NUM_WORKERS \
--bind=unix:$SOCKFILE \
--log-level=debug \
--log-file=-
One of the error I made was actually quite silly because I commented the:
--user=$USER --group=$GROUP
of the line and this behave like the rest of the line was commented also. So basically, everything was in nginx configuration file.
Now fixed. Thanks
Julien
I have gotta my project setup with uwsgi, django, nginx Everything seems to be working fine but somehow I keep on getting the error on getting static files I have been reading through online and tried all the possible ways but I keep on getting this permission denied error on my static folder.
Can someone please let me know what I have done wrong with the permission and how I should change it?
this is my /var/log/nginx/error.log
open() "/root/project/static/*.css" failed (13: Permission denied), client: 2xx.xx.xx.xxx, server: _, request: "GET /static/*.css HTTP/1.1", host: "1xx.xx.xx.xxx"
This is my nginx site-available config
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 = /favicon.ico { access_log off; log_not_found off; }
#location /media {
# root /root/project/mediafiles;
#}
location ^~ /static/ {
allow all; # this is from one of the posts but no luck
auth_basic off; # this is from one of the posts but no luck
root /root/project;
}
location / {
include uwsgi_params;
uwsgi_pass unix:/tmp/uwsgi/project.sock;
}
}
as my folder permission
for project folder it's drwxr-xr-x 23 www-data www-data
for static folder it's drwxr-x--- 8 www-data www-data 4096 May 23 14:40 static
I never made the permission to static 755 too but no luck.
Anyways, this is using root as user instead of having an extra user and root is also in group of www-data
Thanks in advance for all the help.
EDIT:
As suggested this is the output of ps aux | grep nginx
root 810 0.0 0.0 124972 1440 ? Ss 02:18 0:00 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
www-data 811 0.0 0.0 125688 4840 ? S 02:18 0:00 nginx: worker process
www-data 812 0.0 0.0 125348 3196 ? S 02:18 0:00 nginx: worker process
root 1159 0.0 0.0 14224 1004 pts/0 S+ 04:25 0:00 grep --color=auto nginx
The problem I am guessing is the fact that your project root directory is at /root. The default permissions for /root are:
drwx------ 14 root root 4096 May 8 12:47 root
As you can see, other users, such as www-data don't even have read access to the /root directory. In Linux FS, if you need to read something at a path/a/b/c, you need to have read access to each of the folders in that path.
The Nginx worker process runs as user www-data which is trying to open a file that is rooted at /root where this user does not have read permissions, and therefore raising a Permission denied (13).
See this demo for more detail:
$ cat /root/test2/text.txt
cat: /root/test2/text.txt: Permission denied
$ sudo cat /root/test2/test.txt
A
$ sudo ls -la /root/ | grep test2
drwxrwxrwx 2 root root 4096 May 24 02:04 test2
Hope this makes sense. The solution would be on of the following:
Run nginx workers as root (not recommended)
Move your project directory to a location that is designed to be accessed by multiple users such as /usr/local/share or /var/www/ (recommended)
I have the same problem. My nginx server on Centos 7.6 can't access to static folder in path /home/user/app/mysyte/static/. In /var/log/nginx/error.log same error open() "/home/user/app/mysyte/static/*.css" failed (13: Permission denied)
For solving this problem look at this page issue 2
i was running into the same problem and i found this answer useful!
Nginx connet to .sock failed (13:Permission denied) - 502 bad gateway
What I simply did was changing the name of the user on the first line in /etc/nginx/nginx.conf file.
In my case the default user was www-data and I changed it to my root machine username.
I have a project running with NGINX and Django via ajenti. Unfortunately i am not able to traverse the static directory. I have set index on and tried to traverse it manually but i am stuck in the same directory.
NGINX config:
server {
listen *:80 default_server;
server_name testsite.com;
access_log /var/log/nginx/testsite.access.log;
error_log /var/log/nginx/testsite.error.log;
root /var/www/servers/testsite.com/testsite;
index index.html index.htm index.php;
location / {
proxy_pass http://unix:/var/run/ajenti-v-gunicorn-testsite-python-wsgi-0.sock;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location ~ /static/ {
alias /var/www/servers/testsite.com/testsite/public/static/;
autoindex on;
}
}
gunicorn processes:
root 2829 0.9 2.4 57896 12312 ? S 13:25 0:00 /var/www/servers/testsite.com/env/bin/python /var/www/servers/testsite.com/env/bin/gunicorn -c /etc/gunicorn.ajenti.d//testsite_python_wsgi_0.py testsite.wsgi
www-data 2842 2.1 5.0 83572 25928 ? S 13:25 0:00 /var/www/servers/testsite.com/env/bin/python /var/www/servers/testsite.com/env/bin/gunicorn -c /etc/gunicorn.ajenti.d//testsite_python_wsgi_0.py testsite.wsgi
www-data 2849 1.9 4.7 82056 24208 ? S 13:25 0:00 /var/www/servers/testsite.com/env/bin/python /var/www/servers/testsite.com/env/bin/gunicorn -c /etc/gunicorn.ajenti.d//testsite_python_wsgi_0.py testsite.wsgi
www-data 2858 1.8 4.7 82064 24212 ? S 13:25 0:00 /var/www/servers/testsite.com/env/bin/python /var/www/servers/testsite.com/env/bin/gunicorn -c /etc/gunicorn.ajenti.d//testsite_python_wsgi_0.py testsite.wsgi
NGINX processes:
ps -ef | grep nginx
root 29364 1 0 11:40 ? 00:00:00 nginx: master process /usr/sbin/nginx
www-data 29365 29364 0 11:40 ? 00:00:00 nginx: worker process
root 29378 26678 0 11:43 pts/0 00:00:00 grep nginx
Directory permission:
ls -ls
total 52
36 -rwxrwxrwx 1 www-data www-data 36864 Apr 10 10:58 db.sqlite3
4 -rwxrwxrwx 1 www-data www-data 250 Apr 10 10:58 manage.py
4 drwxrwxrwx 3 www-data www-data 4096 Apr 10 10:59 public
4 drwxrwxrwx 2 www-data www-data 4096 Apr 10 11:29 testsite
4 -rwxrwxrwx 1 www-data www-data 169 Apr 10 11:08 testsite.wsgi
Image showing that its impossible to traverse the directory.
Try including this in your urls.py file:
admin_media_path = os.path.join(django.__path__[0], 'contrib', 'admin', 'static', 'admin')
urlpatterns = patterns('',
url(r'^static/admin/(?P<path>.*)$', 'django.views.static.serve', {
'document_root': admin_media_path,
}),
)
This should do the trick.
Hi~ I'm deploying a website in CentOS 6.5. The framework is django1.7. I use nginx and uwsgi.
The website is now available except 403 Forbidden for all static files.
I have googled a few hours, and have changed the whole site folder as chmod 777. The owner of folder is kltc, and user in nginx.conf is also kltc.
I have no idea why the problem is still Permission denied.
nginx.conf
user kltc;
worker_processes 1;
kuaileticao.miyayx.me
server {
# the port your site will be served on
listen 80;
# the domain name it will serve for
server_name kuaileticao.miyayx.me; # substitute your machine's IP address or FQDN
charset utf-8;
access_log /srv/www/nginx/kuaileticao.miyayx.me/access.log;
error_log /srv/www/nginx/kuaileticao.miyayx.me/error.log;
location /static {
autoindex on;
alias /home/kltc/Project/sunny_sports/sunny_sports/static;
}
# Finally, send all non-media requests to the Django server.
location / {
uwsgi_pass 127.0.0.1:8001;
include uwsgi_params; # the uwsgi_params file you installed
}
}
uwsgi.ini
[uwsgi]
# the base directory (full path)
chdir=/home/kltc/Project/sunny_sports
# Django's wsgi file
module=sunny_sports.wsgi:application
master=true
# maximum number of worker processes
processes=10
# the socket (use the full path to be safe
socket=127.0.0.1:8001
chmod-socket=664
chown-socket=kltc:kltc
pidfile=/tmp/project-master.pid
# clear environment on exit
vacuum=true
max-requests=5000
daemonize=sunny_sports.uwsgi.log
error.log
[error] 34335#0: *73 open() "/home/kltc/Project/sunny_sports/sunny_sports/static/css/font-awesome.min.css" failed (13: Permission denied), client: 157.7.154.194, server: kuaileticao.miyayx.me, request: "GET /static/css/font-awesome.min.css HTTP/1.1", host: "kuaileticao.miyayx.me", referrer: "http://kuaileticao.miyayx.me/"
[kltc#localhost static]$ pwd
/home/kltc/Project/sunny_sports/sunny_sports/static
[kltc#localhost static]$ ls -l
total 32
4 drwxrwxrwx. 2 kltc kltc 4096 Feb 25 18:51 avatars
4 drwxrwxrwx. 7 kltc kltc 4096 Feb 25 18:51 css
4 drwxrwxrwx. 2 kltc kltc 4096 Feb 25 18:51 custom
4 drwxrwxrwx. 2 kltc kltc 4096 Feb 25 18:51 font
4 drwxrwxrwx. 2 kltc kltc 4096 Feb 25 18:51 fonts
4 drwxrwxrwx. 3 kltc kltc 4096 Feb 25 18:51 images
4 drwxrwxrwx. 2 kltc kltc 4096 Feb 25 18:51 img
4 drwxrwxrwx. 10 kltc kltc 4096 Feb 26 08:18 js
>
[kltc#localhost static]$ ps -aux | grep nginx
root 37444 0.0 0.0 110008 2048 ? Ss 09:02 0:00 nginx: master process /usr/sbin/nginx
kltc 37445 0.0 0.0 112548 3700 ? S 09:02 0:00 nginx: worker process
I have tried several methods. Such as, change the nginx.conf user to root. But none of them worked.
Hope for your help. Thank you!
Make sure that you chown parent directory of your project (/home) to be readable by the nginx worker.
chown -R kltc:kltc /home
chmod -R ug+r /home
Make sure that you have the STATIC_ROOT declared in your settings file.
Also, try running python manage.py collectstatic --noinputbefore running the server.
Hope that works!