安装nginx:
yum -y install nginx
编辑:vim /etc/nginx/nginx.conf
user root root;
worker_processes auto;error_log /var/log/nginx/error.log;pid /run/nginx.pid;worker_rlimit_nofile 65535;include /usr/share/nginx/modules/*.conf;
events {
worker_connections 65535; multi_accept on; use epoll;}http {
include mime.types; default_type application/octet-stream; server_tokens off; server_names_hash_bucket_size 128; client_header_buffer_size 32k; large_client_header_buffers 4 32k; client_max_body_size 20m; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 30;log_format main "[$time_local] - " "$request - " "$status - " "$request_time - " "$body_bytes_sent - " "$http_referer - " "$sent_http_location - " "$http_user_agent - " "$remote_addr - " "$http_x_forwarded_for - " "$upstream_addr - " "$upstream_status - " "$upstream_response_time - ";
access_log /var/log/nginx/access.log main;gzip on;
gzip_comp_level 2; gzip_http_version 1.1; gzip_types text/plain application/x-javascript text/css application/xml text/javascript; gzip_proxied any; gzip_vary on;proxy_cache_path /var/cache/nginx/cache levels=1:2 keys_zone=tmp_cache:1024m inactive=20m max_size=1024m;
add_header X-Frame-Options SAMEORIGIN; proxy_next_upstream error timeout; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_connect_timeout 180; proxy_send_timeout 180; proxy_read_timeout 180; proxy_buffering on; proxy_buffer_size 8k; proxy_buffers 8 64k; proxy_busy_buffers_size 128k; proxy_temp_file_write_size 128k;upstream XXX-admin {
ip_hash; server 192.168.1.1:8001 max_fails=3 fail_timeout=30s; server 192.168.1.2:8001 max_fails=3 fail_timeout=30s; } upstream socketio_nodes { ip_hash; server 192.168.1.1:5555; server 192.168.1.1:5556; server 192.168.1.1:5557; server 192.168.1.1:5558; server 192.168.1.2:5555; server 192.168.1.2:5556; server 192.168.1.2:5557; server 192.168.1.2:5558; } include /etc/nginx/conf.d/*.conf;}
编辑系统配置文件:vim /etc/nginx/conf.d/XXX.conf
map $http_upgrade $connection_upgrade {
default upgrade; '' close;}server {
listen *:80; server_name *.XXXXX.com *.XXXXX.com.cn; access_log /var/log/nginx/XXX.access.log main; error_log /var/log/nginx/XXX.error.log; root /app/XXX/XXX_web/dist; index index.html;add_header Access-Control-Allow-Origin http://XXX.XXXXX.com;
add_header Access-Control-Allow-Headers Authorization,Content-Type,Accept,Origin,User-Agent,DNT,Cache-Control,X-Mx-ReqToken,X-Data-Type,X-Auth-Token,X-Requested-With; add_header Access-Control-Allow-Methods GET,POST,OPTIONS,HEAD,PUT,DELETE; add_header Access-Control-Allow-Credentials true;location / {
root /app/XXX/XXX_web/dist; index index.html; try_files $uri $uri/ /index.html last; }location ^~ /api {
uwsgi_pass XXX-admin; uwsgi_send_timeout 600; uwsgi_connect_timeout 600; uwsgi_read_timeout 600; include uwsgi_params; uwsgi_param UWSGI_PYHOME /app/XXX/venv; uwsgi_param UWSGI_CHDIR /app/XXX; uwsgi_param UWSGI_SCRIPT XXX:app; uwsgi_param SCRIPT_NAME ""; }location /socket.io {
proxy_pass http://socketio_nodes/socket.io; proxy_http_version 1.1; proxy_buffering off; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "Upgrade";}
}
server {
listen 80; server_name _; access_log /var/log/nginx/nginx.log main; error_log /var/log/nginx/nginx.err; return 400;}把文件中的XXXXX换成你的域名,把XXX换成你的系统名称
手动安装uwsgi服务
- 先决条件
- 安装了python
- 安装了python-devel
- 安装了pip
- 获取uwsgi最新的源码包: uwsgi-2.0.17.1.tar.gz
- pip install uwsgi-2.0.17.1.tar.gz
- 创建 /usr/lib/systemd/system/uwsgi.service 文件,内容为
[Unit]
Description=uWSGI Emperor Service
After=syslog.target
[Service]
EnvironmentFile=-/etc/sysconfig/uwsgi
ExecStartPre=/bin/mkdir -p /run/uwsgi
ExecStartPre=/bin/chown uwsgi:uwsgi /run/uwsgi
ExecStart=/usr/bin/uwsgi --ini /etc/uwsgi.ini
ExecReload=/bin/kill -HUP $MAINPID
KillSignal=SIGINT
Restart=always
Type=notify
StandardError=syslog
NotifyAccess=all
[Install]
WantedBy=multi-user.target
- 新建 /etc/uwsgi.d/ 文件夹, /etc/uwsgi.ini 文件
[uwsgi]
uid = root
gid = root
socket = /var/run/uwsgi/uwsgi.socket
pidfile = /var/run/uwsgi/uwsgi.pid
emperor = /etc/uwsgi.d
#emperor-tyrant = true
master = true
autoload = true
log-date = true
logto = /var/log/uwsgi.log
- XXX相关配置
1) /etc/nginx/conf.d/XXX.conf
map $http_upgrade $connection_upgrade {
default upgrade; '' close;}server {
listen *:80; server_name *.XXXXX.com *.XXXXX.com.cn; access_log /var/log/nginx/XXX.access.log main; error_log /var/log/nginx/XXX.error.log; root /app/XXX/XXX_web/dist; index index.html;add_header Access-Control-Allow-Origin http://XXX.XXXXX.com;
add_header Access-Control-Allow-Headers Authorization,Content-Type,Accept,Origin,User-Agent,DNT,Cache-Control,X-Mx-ReqToken,X-Data-Type,X-Auth-Token,X-Requested-With; add_header Access-Control-Allow-Methods GET,POST,OPTIONS,HEAD,PUT,DELETE; add_header Access-Control-Allow-Credentials true;location / {
root /app/XXX/XXX_web/dist; index index.html; try_files $uri $uri/ /index.html last; }location ^~ /api {
uwsgi_pass XXX-admin; uwsgi_send_timeout 600; uwsgi_connect_timeout 600; uwsgi_read_timeout 600; include uwsgi_params; uwsgi_param UWSGI_PYHOME /app/XXX/venv; uwsgi_param UWSGI_CHDIR /app/XXX; uwsgi_param UWSGI_SCRIPT XXX:app; uwsgi_param SCRIPT_NAME ""; }location /socket.io {
proxy_pass http://socketio_nodes/socket.io; proxy_http_version 1.1; proxy_buffering off; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "Upgrade";}
}
server {
listen 80; server_name _; access_log /var/log/nginx/nginx.log main; error_log /var/log/nginx/nginx.err; return 400;}2) /etc/uwsgi.d/XXX.ini
[uwsgi]
chdir = /app/XXX/wsgi-file = /app/XXX/XXX.pyhome = /app/XXX/venvhttp-websockets = true
virtualenv = /app/XXX/venvcallable = appvacuum = trueuwsgi-socket = 0.0.0.0:8001
socket = /run/uwsgi/XXX.sockbuffer-size = 65535
master = false
enable-threads = true
processes = 4
threads = 2thunder-lock = true
plugins = python
lazy-apps = true
3) /etc/uwsgi.d/XXX-socket.ini
[uwsgi]
gevent=1000gevent-monkey-patch=truehttp=:5555http=:5556http=:5557http=:5558http-websockets=truemaster=truechdir=/app/XXX/virtualenv=/app/XXX/venvbuffer-size=65535thunder-lock=truevacuum=truewsgi-file=XXX_SOCKET.pycallable=app
本应用起了websocket,如果没有的可以去除相关配置