Nginx Configure
1.主配置/etc/nginx.conf
#/etc/nginx/nginx.conf user nginx; worker_processes auto; error_log /var/log/nginx/error.log; pid /run/nginx.pid; # Load dynamic modules. See /usr/share/nginx/README.dynamic. 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"'; log_format main '[$time_iso8601] $remote_addr "$request" ' '$status $request_time $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; gzip on; gzip_comp_level 6; gzip_min_length 1024; gzip_types *; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; proxy_headers_hash_max_size 1024; proxy_headers_hash_bucket_size 512; server_names_hash_bucket_size 512; include /etc/nginx/mime.types; default_type application/octet-stream; # Load modular configuration files from the /etc/nginx/conf.d directory. # See http://nginx.org/en/docs/ngx_core_module.html#include # for more information. include /etc/nginx/conf.d/*.conf; include /etc/nginx/vhosts/*.conf; }
2.网站配置
# /etc/nginx/vhosts/my.domain.com.conf server { listen 80; server_name my.domain.com; return 301 https://$host$request_uri; access_log /var/log/nginx/my.domain.com.access.log main; error_log /var/log/nginx/my.domain.com.error.log; location / { proxy_pass http://localhost:3031/; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-Port $server_port; } location /static/ { alias /var/www/my.domain.com/static/; autoindex off; } location /.well-known/ { alias /var/www/my.domain.com/.well-known/; autoindex off; } } server { listen 443 ssl; server_name my.domain.com; access_log /var/log/nginx/my.domain.com.access.log main; error_log /var/log/nginx/my.domain.com.error.log; ssl_certificate "/root/.getssl/my.domain.com/my.domain.com.chain.crt"; ssl_certificate_key "/root/.getssl/my.domain.com/my.domain.com.key"; ssl_session_cache shared:SSL:20m; ssl_session_timeout 60m; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; ssl_ciphers "ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:ECDHE-ECDSA-DES-CBC3-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA:!DSS"; location / { proxy_pass http://localhost:3031/; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-Port $server_port; } # proxy pass php location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $host; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } location /static/ { alias /var/www/my.domain.com/static/; autoindex off; } location /.well-known/ { alias /var/www/my.domain.com/.well-known/; autoindex off; } location ~* \.html$ { root /var/www/my.domain.com/; autoindex off; } location /robots.txt { root /var/www/my.domain.com/; autoindex off; } }
记录经验、开心工作 | 个人博客