编辑 /etc/nginx/nginx.conf ,在http区域下添加 server_tokens off; 隐藏版本号。
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/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 /var/log/nginx/access.log main;
#隐藏Nginx的版本号
server_tokens off;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
在 /etc/nginx/conf.d/ 下添加网站配置文件,以下是一般情况下的示例配置,根据实际情况修改。
server {
listen 80;
listen 443 ssl;
server_name abc.com www.abc.com;
ssl_certificate /etc/nginx/ssl/abc.com.pem;
ssl_certificate_key /etc/nginx/ssl/abc.com.key;
charset utf-8;
#access_log /var/log/nginx/host.access.log main;
# 以abc.com开头的网址跳转到https完整路径
if ($host ~* "^abc.com" ) {
return 301 https://www.abc.com$request_uri;
}
# http协议网址跳转到https
if ($scheme = "http") {
return 301 https://www.abc.com$request_uri;
}
root /project/public;
index index.html index.php;
# Laravel项目-正式上线前请先测试
location / {
# 请求的文件不存在,则将请求转发的内部的index.php
try_files $uri $uri/ /index.php?$query_string;
}
# thinkphp项目
#location / {
# if (!-e $request_filename) {
# rewrite ^/(.*)$ /index.php?s=$1 last;
# break;
# }
#}
# vue项目-正式上线前请先测试
#location / {
# try_files $uri $uri/ /index.html;
#}
error_page 497 https://www.abc.com$request_uri;
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~* ^/(uploads|templets|data)/.*.(php|php5)$ {
return 301 https://www.abc.com$request_uri;
}
# 代理服务器-根据需要配置
location ~ /api/ {
proxy_http_version 1.1;
proxy_set_header Connection "keep-alive";
# 将客户端host及ip信息转发到对应节点
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# 转发Cookie,设置 SameSite 此项根据需要设置
# proxy_cookie_path / "/; secure; HttpOnly; SameSite=strict";
# 代理访问真实服务器
proxy_pass http://127.0.0.1:8888;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
本文为LinWord原创文章,转载无需和我联系,但请注明来自LinWord博客https://www.linword.com
最新评论