Воспроизводится оригинальный адрес: https://www.cnblogs.com/hailang8/p/8664413.html
1, установка: ни -y установить Nginx
![](https://images2018.cnblogs.com/blog/679720/201803/679720-20180328155814663-705469438.png)
![](https://images2018.cnblogs.com/blog/679720/201803/679720-20180328155836513-1810896086.png)
![](https://images2018.cnblogs.com/blog/679720/201803/679720-20180328155856155-1163936784.png)
![](https://images2018.cnblogs.com/blog/679720/201803/679720-20180328155907943-1654573397.png)
![](https://images2018.cnblogs.com/blog/679720/201803/679720-20180328155918714-388003925.png)
![](https://images2018.cnblogs.com/blog/679720/201803/679720-20180328155929082-741390725.png)
![](https://images2018.cnblogs.com/blog/679720/201803/679720-20180328155946299-793757958.png)
Последний рекомендуется кожаной конфигурация Nginx сайта, чтобы понять и использовать нужно иметь какой-то фундамент.
nginxconfig.io
Наконец, я отправил о родовом шаблоне конфигурации nginx.conf
# Generated by nginxconfig.io
# https://nginxconfig.io/?0.domain=_&0.path=%2Froot%2Fnginx&0.document_root=%2Fhtml&0.redirect=false&0.https=false&0.php=false&0.index=index.html&0.fallback_html&0.access_log_domain&0.error_log_domain&user=root&file_structure=unified
user root;#centos用户,看需修改
pid /run/nginx.pid;
worker_processes auto;
worker_rlimit_nofile 65535;
events {
multi_accept on;
worker_connections 65535;
}
http {
charset utf-8;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
server_tokens off;
log_not_found off;
types_hash_max_size 2048;
client_max_body_size 16M;
# MIME
include mime.types;
default_type application/octet-stream;
# logging
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log warn;
# load configs
include /etc/nginx/conf.d/*.conf;
# _
server {
listen 80;
listen [::]:80;
server_name _;
root /root/nginx/html;#html页面根目录,看需修改
# security headers
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-XSS-Protection "1; mode=block" always;
add_header X-Content-Type-Options "nosniff" always;
add_header Referrer-Policy "no-referrer-when-downgrade" always;
add_header Content-Security-Policy "default-src 'self' http: https: data: blob: 'unsafe-inline'" always;
# . files
location ~ /\.(?!well-known) {
deny all;
}
# logging
access_log /var/log/nginx/_.access.log;
error_log /var/log/nginx/_.error.log warn;
# index.html fallback
location / {
try_files $uri $uri/ /index.html;
}
# favicon.ico
location = /favicon.ico {
log_not_found off;
access_log off;
}
# robots.txt
location = /robots.txt {
log_not_found off;
access_log off;
}
# assets, media
location ~* \.(?:css(\.map)?|js(\.map)?|jpe?g|png|gif|ico|cur|heic|webp|tiff?|mp3|m4a|aac|ogg|midi?|wav|mp4|mov|webm|mpe?g|avi|ogv|flv|wmv)$ {
expires 7d;
access_log off;
}
# svg, fonts
location ~* \.(?:svgz?|ttf|ttc|otf|eot|woff2?)$ {
add_header Access-Control-Allow-Origin "*";
expires 7d;
access_log off;
}
# gzip
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_types text/plain text/css text/xml application/json application/javascript application/rss+xml application/atom+xml image/svg+xml;
}
}
![](https://images2018.cnblogs.com/blog/679720/201803/679720-20180328155814663-705469438.png)
![](https://images2018.cnblogs.com/blog/679720/201803/679720-20180328155836513-1810896086.png)
![](https://images2018.cnblogs.com/blog/679720/201803/679720-20180328155856155-1163936784.png)
![](https://images2018.cnblogs.com/blog/679720/201803/679720-20180328155907943-1654573397.png)
![](https://images2018.cnblogs.com/blog/679720/201803/679720-20180328155918714-388003925.png)
![](https://images2018.cnblogs.com/blog/679720/201803/679720-20180328155929082-741390725.png)
![](https://images2018.cnblogs.com/blog/679720/201803/679720-20180328155946299-793757958.png)