下面是我的Nginx配置,我目前使用 http://wqjp.lefe.wang:4001/api/store/get 可以请求到数据,但是我使用 http://wqjp.lefe.wang/api/store/get 却报404错误。Https同样的错误。谢谢了。其实我想做的就是接口 【 http://wqjp.lefe.wang:4001/api/store/get 】可以不使用端口就可以访问【 http://wqjp.lefe.wang:4001/api/store/get 】。
#user nobody;
worker_processes 1;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name wqjp.lefe.wang;
location / {
root /home/ubuntu/nodeserver/WJCar_node/WJCar;
index app.js;
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;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://127.0.0.1:4001;
proxy_redirect off;
}
}
# HTTPS server
server {
listen 443;
server_name https://wqjp.lefe.wang;
ssl on;
ssl_certificate /home/ubuntu/nodeserver/WJCar_node/WJCar/res/1_wqjp.lefe.wang_bundle.crt;
ssl_certificate_key /home/ubuntu/nodeserver/WJCar_node/WJCar/res/2_wqjp.lefe.wang.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
location / {
root /home/ubuntu/nodeserver/WJCar_node/WJCar;
index app.js;
proxy_redirect off;
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_pass https:118.89.23.181:4000;
}
}
}
我一般server_name 不加 http://
@mabu233 我试过了,不加也不可以的,谢谢,不知道为什么呢
去掉 http://, 然后 http:// wqjp.lefe.wang; 之间还多了一个空格, 加上 http://, nginx不会报错,但是会警告 “has suspicious symbols”,这个导致域名访问404
@vincentLiuxiang 同学你好,按你说的,改了,但是还是不可以,不过还是谢谢
root /home/ubuntu/nodeserver/WJCar_node/WJCar; index app.js;
server {
listen 80;
server_name m.008.al;
location / {
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;
proxy_set_header X-Nginx-Proxy true;
proxy_set_header Connection "";
proxy_pass http://172.17.0.7;
}
}
root index 是静态服务需要的选项。
@lefex 加了http://一定会有问题,如果去掉之后还有问题,那你贴一个完整的配置来看看, 像https里面,这种 proxy_pass https:118.89.23.181:4000; 都语法错误了。
server不放http里吗?
来自酷炫的 CNodeMD