nginx-1.20.1 conf 注意 , windows 底下 路径要写 左斜杠, 像这样
location / {
root G:/project/springbootProj/bankedback/src/main/resources/static/dist;
index index.html index.htm;
}
这样不行
G:\project\springbootProj\bankedback\src\main\resources\static\dist;
要注意端口 默认的 80 可能被占用
要是没有跳出让你授权的界面 应该就是没有启动成功。 在conf里配置端口,配置前可以先看看哪些端口没有被占用
比如
netstat -ano |findstr :8084
G:\software\nginx-1.20.1>netstat -ano |findstr :8084
TCP 0.0.0.0:8084 0.0.0.0:0 LISTENING 7772
G:\software\nginx-1.20.1>netstat -ano |findstr :8085
很可能出现的 403 forbidden 问题, 请看 。
链接: 解决Nginx出现403 forbidden (13: Permission denied)报错的四种方法.
我是第一种方法解决的
nginx中使用pfx格式的ssl证书
https://www.cnblogs.com/heartlifes/articles/6970858.html
配置文件
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
# 这里注意 , 要配置为root,就是你是哪个用户启动的就哪个用户的名字
# 实际上正常来说应该 useradd 一个 nginx 用户才对。。。
user root;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
# 如果你的服务器已经配置了域名,ssl什么的,那就不要配http的了,直接配https
# https 要配置的就 ssl_certificate 和 ssl_certificate_key 和 location /
http {
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;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
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;
# http 要注意端口有没有被占用 配置之前 先 看端口
# 比如 lsof -i:8082
# 使用没有被占用的 , 并且注意打开服务器的防火墙(安全组),比如阿里云服务器的 防火墙(安全组)
# 要配置的就 listen 和 location /
# server {
# 要配置的 listen
# listen 8080 default_server;
# listen [::]:8080 default_server;
# server_name 可以不去管它
# server_name _;
# root 注释掉了 貌似没事
# # root /usr/share/nginx/html;
#
# # Load configuration files for the default server block.
# include /etc/nginx/default.d/*.conf;
# 主要配置了 location /
# location / {
# root /home/xxx/dist;
# index index.html index.htm;
# }
# error_page 404 /404.html;
# location = /40x.html {
# }
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# }
# }
# Settings for a TLS enabled server.
#
server {
listen 443 ssl http2 default_server;
listen [::]:443 ssl http2 default_server;
server_name _;
# root 注释掉 貌似没事
# root /usr/share/nginx/html;
# ssl_certificate "/etc/pki/nginx/server.crt";
# 要配置的就 ssl_certificate 和 ssl_certificate_key 和 location /
ssl_certificate "你的.crt 文件位置";
ssl_certificate_key ".rsa文件位置";
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 10m;
ssl_ciphers PROFILE=SYSTEM;
ssl_prefer_server_ciphers on;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
root /home/xxx/dist;
index index.html index.htm;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
}
/usr/share/nginx
是 nginx 的目录,里面有个 html,那么相对路径就是相对他的