[英]Getting nginx and node.js to play nice
我正在嘗試配置一個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。 Express應用程序位置: / var / www / html / myNodeAppRoot
這是我的/etc/nginx/sites-available/api.mysite.com文件(符號鏈接到啟用了sites的文件):
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;
}
}
謝謝你的幫助!
我在同一台服務器上運行了一堆Node.js應用程序,而nginx提供了一些靜態內容。 這是我的設置:
# the meteor server
server {
server_name example.com;
access_log /etc/nginx/logs/example.access;
error_log /etc/nginx/logs/example.error error;
location / {
proxy_pass http://localhost:3030;
proxy_set_header X-Real-IP $remote_addr;
}
}
我只是重復此代碼塊,並為每個新的Node.js應用程序更改端口。 然后,我使用不同的--port 3030
參數運行Node.js。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.