[英]Nginx node setup to custom directory
我是第一次使用nginx,因此需要幫助。
我的應用程序在/ root / project1 / tools中運行 (此目錄包含server.js)
我如何將Nginx連接到此目錄。 我搜索了很多,但沒有找到直接的答案。 認為nginx將通過端口號而不是路徑找到我的server.js。 真的嗎?
我正在使用linux ubuntu 18
Nginx引發錯誤
2018/10/23 06:14:51 [alert] 3822#3822:* 2025在連接到上游時socket()失敗(24:打開文件太多),客戶端:127.0.0.1,服務器:nativeiconba $
/etc/nginx/sites-available/nativeiconbase.com
upstream app_yourdomain {
server 127.0.0.1:8080;
keepalive 8;
}
# the nginx server instance
server {
listen 80;
listen [::]:80;
server_name nativeiconbase.com www.nativeiconbase.com;
access_log /var/log/nginx/nativeiconbase.com.log;
# pass the request to the node.js server with the correct headers
# and much more can be added, see nginx config options
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_pass http://nativeiconbase/;
proxy_redirect off;
}
}
root /root/project1/src/;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name localhost;
在/ etc / nginx的/網站可用/默認
server {
listen 80 default_server;
listen [::]:80 default_server;
# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;
root /root/project1/src/;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
location / {
# First attempt to serve request as file, then
proxy_pass http://10.139.32.25:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
我的節點應用程序正在端口8080上運行。任何想法我該怎么做才能設置nginx。 對資源的任何引用都會有所幫助。
您所需要做的就是在Nginx中設置反向代理服務器
在任何端口上啟動NodeJS Server
node server.js
如果您使用的是諸如pm2
類的任何流程管理工具,那么
pm2 server.js
現在在nginx config中,您要做的就是將所有請求代理到本地nodejs服務器,這樣
upstream app_yourdomain {
server 127.0.0.1:8080;
keepalive 8;
}
# the nginx server instance
server {
listen 80;
listen [::]:80;
server_name nativeiconbase.com www.nativeiconbase.com;
access_log /var/log/nginx/nativeiconbase.com.log;
# pass the request to the node.js server with the correct headers
# and much more can be added, see nginx config options
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_pass http://localhost:8080;
proxy_redirect off;
}
}
我剛剛在您的代碼中更改了proxy_pass http://localhost:8080
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.