Mit*_*len 2 nginx uwsgi systemctl
我最近有了一台 Ubuntu 18 服务器,至少可以说我有点困惑。
第一:如果我运行sudo service nginx start
或sudo systemctl start nginx
,一切似乎都有效。我的网站加载,并且都sudo service nginx status
和sudo systemctl status nginx
返回的所有明确的信息。
现在的问题是:当我重新启动我的服务器时,nginx
不会自动启动,因为网站没有被加载。我试过sudo systemmctl enable nginx
又试了一次重新启动。同样,nginx
由于网站未加载而未运行。
事实上,如果我重新启动我的服务器sudo reboot
然后sudo service nginx status
或者sudo systemctl status nginx
我收到一条错误消息。尽管有错误消息,但我可以运行sudo service nginx start
或者sudo systemctl start nginx
它会全部恢复工作。
我收到的错误消息如下:
(venv) user@server:/data/project$ sudo systemctl status nginx
? nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Tue 2019-02-26 17:50:18 CET; 1min 6s ago
Docs: man:nginx(8)
Process: 830 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=1/FAILURE)
Feb 26 17:50:18 md3.tudelft.nl systemd[1]: Starting A high performance web server and a reverse proxy server...
Feb 26 17:50:18 md3.tudelft.nl nginx[830]: nginx: [emerg] open() "/data/project/uwsgi_params" failed (2: No such file or directory) in /etc/nginx/sites-enabled/paintingViewer.conf
Feb 26 17:50:18 md3.tudelft.nl nginx[830]: nginx: configuration file /etc/nginx/nginx.conf test failed
Feb 26 17:50:18 md3.tudelft.nl systemd[1]: nginx.service: Control process exited, code=exited status=1
Feb 26 17:50:18 md3.tudelft.nl systemd[1]: nginx.service: Failed with result 'exit-code'.
Feb 26 17:50:18 md3.tudelft.nl systemd[1]: Failed to start A high performance web server and a reverse proxy server.
Run Code Online (Sandbox Code Playgroud)
嗯,这看起来很简单:它找不到 uwsgi_params 文件。uwsgi_params 文件确实存在,而且它位于正确的位置。
我的nginx
.conf 文件:
# the upstream component nginx needs to connect to
upstream django {
server unix:///data/project/paintingViewer.sock; # for a file socket
# server 127.0.0.1:8001; # for a web port socket -> works if we use Djano's build in webserver.
}
# configuration of the server
server {
# the port your site will be served on
listen 80;
# the domain name it will serve for
server_name server;
charset utf-8;
# max upload size
client_max_body_size 75M; # adjust to taste
# Django media
location /media {
alias /data/project/media; # your Django project's media files - amend as required
}
location /static {
alias /data/project/static; # your Django project's static files - amend as required
}
# Finally, send all non-media requests to the Django server.
location / {
uwsgi_pass django;
include /data/project/uwsgi_params; # the uwsgi_params file you installed
}
}
Run Code Online (Sandbox Code Playgroud)
该/data/project/uwsgi_params
文件是:
uwsgi_param QUERY_STRING $query_string;
uwsgi_param REQUEST_METHOD $request_method;
uwsgi_param CONTENT_TYPE $content_type;
uwsgi_param CONTENT_LENGTH $content_length;
uwsgi_param REQUEST_URI $request_uri;
uwsgi_param PATH_INFO $document_uri;
uwsgi_param DOCUMENT_ROOT $document_root;
uwsgi_param SERVER_PROTOCOL $server_protocol;
uwsgi_param REQUEST_SCHEME $scheme;
uwsgi_param HTTPS $https if_not_empty;
uwsgi_param REMOTE_ADDR $remote_addr;
uwsgi_param REMOTE_PORT $remote_port;
uwsgi_param SERVER_PORT $server_port;
uwsgi_param SERVER_NAME $server_name;
Run Code Online (Sandbox Code Playgroud)
现在,有几件事我不明白:
1)nginx
如果我运行start
命令,它怎么可能工作,但nginx
在启动时不起作用?
2)无法找到文件的status
读取,而它在一个?nginx
uwsgi
start
3) 我怎样才能nginx
在重新启动时正常运行?
Nginx 无法找到该文件,因为启动后挂载/外部文件系统未准备好。要告诉 nginx 等待挂载,请使用systemctl edit nginx.service
并添加以下行:
[Unit]
RequiresMountsFor=<mountpoint>
Run Code Online (Sandbox Code Playgroud)
或者在您的特定情况下:
[Unit]
RequiresMountsFor=/data
Run Code Online (Sandbox Code Playgroud)
nginx 现在/data
将在启动之前始终等待准备就绪。
归档时间: |
|
查看次数: |
3233 次 |
最近记录: |