使用 yum 自动安装 nginx
yum -y install nginx
配置 Nginx
配置其属性
# vim /usr/local/webserver/nginx/conf/nginx.conf user root; worker_processes 1; error_log /log/nginx/nginx_error.log error; #日志位置和日志级别 worker_rlimit_nofile 1024; events{ use epoll; worker_connections 1024; } 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 /log/nginx/access.log main; keepalive_timeout 0; gzip on; gzip_min_length 1k; gzip_buffers 4 16k; gzip_http_version 1.0; gzip_comp_level 2; gzip_types text/plain application/javascript text/css application/xml; gzip_vary on; server { # 默认重定向到https listen 80; server_name xxx.yyy; return 301 <https://xxx.yyy>; } server { listen 443 ssl; server_name xxx.yyy; charset utf-8; ssl_certificate /home/www/xxx.yyy.pem; # 密钥,由HTTPS证书颁发者提供 ssl_certificate_key /home/www/xxx.yyy.key; # 密钥,由HTTPS证书颁发者提供 ssl_session_timeout 5m; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; location / { root /home/www/dist/; index index.html index.htm; } } }
检查配置文件正确性
nginx -t
常用命令
nginx # 启动 nginx -s reload # 重新载入配置文件 nginx -s reopen # 重启 Nginx nginx -s stop # 停止 Nginx