【发布时间】:2014-03-18 21:10:09
【问题描述】:
我有一个正在尝试配置的 nginx/node.js 服务器。基本上这只是在端口 80 上同时运行 2 个 Web 服务器的问题。我有 www.mysite.com,我需要在端口 80 上指向 nginx。但我也有一个 node.js 服务器,我需要 api.mysite.com 指向端口 8888。
我在我的配置 (http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass) 中弄乱了 proxy_pass,但没有运气。我也试过这个https://stackoverflow.com/a/20716524/605841,但没有成功。
如果有人有任何提示,那就太好了。提前致谢。
Nginx 公共目录: /var/www/html. 快速应用位置: /var/www/html/myNodeAppRoot
这是我的 /etc/nginx/sites-available/api.mysite.com 文件(链接到启用站点的符号):
server {
listen 80;
# server_name ~^(?<login>[a-z]+)\.api\.mysite\.com$;
server_name api.mysite.com$;
location / {
# root /var/www/html/myNodeAppRoot;
# proxy_pass http://unix:/tmp/\$login.api.mysite.com.sock:$uri$is_args$args;
proxy_pass http://unix:/tmp/api.mysite.com.sock:$uri$is_args$args;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
这是我的 default.conf 文件:
#
# The default server
#
server {
listen 80 default_server;
server_name www.mysite.com;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root /var/www/html;
index index.php index.html index.htm;
}
error_page 404 /404.html;
location = /404.html {
root /var/www/html;
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root /var/www/html;
try_files $uri =404;
# fastcgi_pass 127.0.0.1:9000;
fastcgi_pass unix:/tmp/php5-fpm.sock;
fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
感谢您的帮助!
【问题讨论】: