Nginx作反向代理的基本配置
Nginx作反向代理的基本配置
server {
listen 80;
server_name xxx.com www.xxx.com;
return 301 https://xxx.com$request_uri;
}
server {
listen 443 ssl;
server_name www.xxx.com;
ssl_certificate /etc/nginx/ssl/xxx.com.pem;
ssl_certificate_key /etc/nginx/ssl/xxx.com.key;
return 301 https://xxx.com$request_uri;
}
server {
server_name xxx.com;
root /usr/share/nginx/html/xxx;
index index.php index.html;
location /api {
proxy_pass http://localhost:9090;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
}
location / {
try_files $uri $uri/ /index.html
}
#error_page 404 /404.html;
listen 443 ssl http2;
ssl_certificate /etc/nginx/ssl/xxx.com.pem;
ssl_certificate_key /etc/nginx/ssl/xxx.com.key;
}