我想要配置一個nginx/node.js服務器。基本上,這只是在同一時間在端口80上運行2個Web服務器的問題。我有www.mysite.com,我需要指向端口80上的nginx。但我也有一個node.js服務器,我需要api.mysite.com指向端口8888.讓nginx和node.js發揮不錯
我搞亂了與我的配置proxy_pass(http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass),但沒有運氣。我也試過這https://stackoverflow.com/a/20716524/605841沒有運氣。
如果有人有任何提示將是偉大的。提前致謝。
Nginx public dir:/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;
}
}
感謝您的幫助!