我已经在我的vps中安装了nginx并配置了php和mysql。我的主页位于/ var / www / html。当我从任何计算机访问它时,它正常工作。
现在我安装了nodejs并设置了一个符合this link
的简单hello世界我的nginx默认文件是
server {
listen 80 default_server;
listen [::]:80 default_server;
location / {
root /var/www/html;
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
#try_files $uri $uri/ =404;
try_files $uri $uri/ = 404 $uri.html $uri/index.html @app;
#proxy_pass http://localhost:3000;
}
location @app {
proxy_pass http://localhost:3000;
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;
}
我的问题是我的php文件被提供或节点文件被提供,而我想,http://ipaddress:80可以提供我的php文件,而http://ipaddress:3000应该为我的nodejs app提供服务。
我正在使用pm2节点模块。 我是nginx的新手。 感谢
答案 0 :(得分:0)
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.php;
location / {
# Redirect everything that isn't a real file to index.php
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#fastcgi_pass 127.0.0.1:9000;
fastcgi_pass unix:/var/run/php5-fpm.sock;
try_files $uri =404;
}
}
server {
listen 3000;
listen [::]:3000;
location / {
proxy_pass http://localhost:3000;
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;
}
}