使用nginx服务
- 安装nginx服务
sudo yum install -y nginx
- 创建nginx配置文件
vim /etc/nginx/nginx.conf
user root;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
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; 允许sendfile方式传输文件,默认为off,可在http,server,location
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
include /etc/nginx/conf.d/*.conf;
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Headers X-Requested-With;
add_header Access-Control-Allow-Headers Content-Type;
add_header Access-Control-Allow-Methods GET,POST,OPTIONS;
server {
listen 89 default_server;
listen [::]:89 default_server;
server_name _;
root /usr/share/nginx/html;
include /etc/nginx/default.d/*.conf;
client_max_body_size 100m;
charset utf-8;
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:8383;
}
location /static {
alias /home/DjangoProject/FMS/static;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
}
- 启动/停止/重启nginx服务
nginx -c /etc/nginx/nginx.conf
nginx -s stop
nginx -s quit
nginx -s reload
- 查看服务进程和监听端口
ps -aux | grep nginx
netstat -ntlp | grep 89
- 开启自启动nginx服务
systemctl enable nginx.conf
- 查看所有开机启动服务
systemctl list-unit-files