常规配置:
server {listen 80;server_name www.test.com;
location / {proxy_pass http://127.0.0.1:3000;root html;proxy_http_version 1.1;proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-Proto https;proxy_set_header X-Forwarded-For $remote_addr;proxy_set_header X-Forwarded-Host $remote_addr;}}
SSL证书配置:
server {listen 443 ssl;server_name 你的域名;
ssl_certificate C:\Certbot\live\***\fullchain.pem;ssl_certificate_key C:\Certbot\live\***\privkey.pem;
ssl_session_timeout 5m;ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;ssl_prefer_server_ciphers on;
location / {proxy_pass http://127.0.0.1:3001;root html;proxy_http_version 1.1;proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-Proto https;proxy_set_header X-Forwarded-For $remote_addr;proxy_set_header X-Forwarded-Host $remote_addr;}}
代理php
upstream php{
server 127.0.0.1:808 weight=1;
}
server {
listen 80;
server_name www.php.com;location / {
proxy_pass http://php;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;}
}
将IP访问和其它非法二级域名跳转到主域名
server {listen 80 default;server_name _;rewrite ^(.*) http://www.test.com$1 permanent;}
http{}其它配置:
#server_name名限制长度
server_names_hash_bucket_size 128;
#上传文件的大小限制 默认1m
client_max_body_size 8m;#连接超时 时间定义 默认秒 默认65秒
keepalive_timeout 60;
#读取客户端请求头数据的超时时间 默认秒 默认60秒
client_header_timeout 15;
#读取客户端请求主体的超时时间 默认秒 默认60秒
client_body_timeout 15;
#响应客户端的超时时间 默认秒 默认60秒
send_timeout 25;
Ubuntu 安装Nginx
在Ubuntu系统上安装Nginx并进行基本配置的步骤如下:
更新包列表:
sudo apt update
安装Nginx:
sudo apt install nginx
启动Nginx服务:
sudo systemctl start nginx
(可选)设置Nginx开机自启:
sudo systemctl enable nginx
配置Nginx(编辑Nginx配置文件):
sudo nano /etc/nginx/sites-available/default
在编辑器中,您可以修改服务器块中的内容来配置您的网站。例如:
server {
listen 80;
server_name example.com;
root /var/www/html;
index index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
}
重启Nginx以应用配置更改:
sudo systemctl restart nginx
确认Nginx正在运行:
sudo systemctl status nginx
Comments | NOTHING