Python的Django安装nginx1.9.3以上版本修改配置文件的操作
在命令行输入sudo apt-get install nginx,显示以下界面,安装成功
使用以下命令行:
cd /etc/nginx
sudo gedit nginx.conf
去找defualt文件修改配置
cd /etc/nginx/sites-enabled/
sudo gedit default修改其中的server
server {
# listen 80 default_server;
listen 127.0.0.1:80 default_server;
# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;
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 / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
# try_files $uri $uri/ =404;
include uwsgi_params;
uwsgi_pass 127.0.0.1:8000;
}
location /static {
alias /var/www/test7/static/;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# include snippets/fastcgi-php.conf;
#
# # With php7.0-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# # With php7.0-fpm:
# fastcgi_pass unix:/run/php/php7.0-fpm.sock;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
修改完成后,返回上一级,默认开启了nginx,需要停止重启
cd ..
开启了会显示端口占用
[email protected]:/etc/nginx$ sudo nginxnginx: [emerg] bind() to 127.0.0.1:80 failed (98: Address already in use)
nginx: [emerg] bind() to 127.0.0.1:80 failed (98: Address already in use)
nginx: [emerg] bind() to 127.0.0.1:80 failed (98: Address already in use)
nginx: [emerg] bind() to 127.0.0.1:80 failed (98: Address already in use)
nginx: [emerg] bind() to 127.0.0.1:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()
查看是否开启
[email protected]:/etc/nginx$ ps ajx|grep nginx1 7362 7362 7362 ? -1 Ss 0 0:00 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
7362 7363 7362 7362 ? -1 S 33 0:00 nginx: worker process
7453 8656 8655 7453 pts/6 8655 S+ 1000 0:00 grep --color=auto nginx
停止nginx
[email protected]:/etc/nginx$ sudo nginx -s stop[email protected]:/etc/nginx$ sudo nginx
修改了nginx配置文件,需要重启nginx
现在nginx已经修改完成,然后创建静态文件的目录在var/www/项目名称/static,
使用一下
- 收集所有静态文件到static_root指定目录:python manage.py collectstatic