【发布时间】:2019-09-28 07:23:14
【问题描述】:
我想在我的 DigitalOcean 服务器(Ubuntu 18.04)上部署 nuxt + laravel 项目。我已经在上面配置了域名和 SSL 证书。我正在寻找正确的 nginx 配置,以便在同一台服务器上为客户端和 API 提供服务。
我为客户端配置了代理,可惜API不可用
# Redirect http to https
server {
listen 80;
listen [::]:80 ipv6only=on default_server;
server_name MY_DOMAIN_NAME;
return 302 https://$server_name$request_uri;
}
# SSL configs
server {
listen 443 ssl http2;
ssl_certificate /etc/nginx/fullchain.pem;
ssl_certificate_key /etc/nginx/MY_DOMAIN_NAME.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers ECDH+AESGCM:ECDH+AES256:ECDH+AES128:DH+3DES:!ADH:!AECDH:!MD5;
# Use our own DH params
ssl_dhparam /etc/nginx/dhparam.pem;
ssl_session_cache shared:SSL:40m;
ssl_session_timeout 4h;
ssl_session_tickets on;
server_name MY_DOMAIN_NAME;
root /var/www/MY_LARAVEL_APP_FOLDER/public;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
index index.html index.htm index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ \.css {
add_header Content-Type text/css;
}
location ~ \.js {
add_header Content-Type application/x-javascript;
}
#client
location / {
expires $expires;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_redirect off;
proxy_read_timeout 1m;
proxy_connect_timeout 1m;
proxy_pass http://127.0.0.1:3000; # set the adress of the Node.js
}
location ~ /\.(?!well-known).* {
deny all;
}
}
我试过这段代码,nginx 说重复的位置/(逻辑)。请帮助我:) 使用代理或不使用代理为 API 和客户端设置服务器的正确方法是什么?
【问题讨论】:
标签: laravel nginx nginx-config nuxt.js