javascript - How to configure nginx to work with Node.js and PHP -
i have problem configuration nginx work node.js , php.
want this:
- user open my-project.com
- node.js server running on port 3001
- request node.js send my-project.com on port 80 http-proxy
- nginx (port 80) server run php scripts , display output users
so want create php server node.js working in background special tasks. don't want node server on subdomain, need run time not particular requests.
my nginx config
server { listen *:80; server_name my-project.com www.my-project.com; client_max_body_size 1m; root /var/www/public; index index.html index.htm index.php; access_log /var/log/nginx/nxv_5rxici0o7b9k.access.log; error_log /var/log/nginx/nxv_5rxici0o7b9k.error.log; location / { proxy_pass http://localhost:3001; ### added line root /var/www/public; try_files $uri $uri/ /index.php$is_args$args; autoindex off; index index.html index.htm index.php; } location ~ \.php$ { root /var/www/public; fastcgi_index index.php; fastcgi_split_path_info ^(.+\.php)(/.*)$; try_files $uri $uri/ /index.php$is_args$args; include /etc/nginx/fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_param script_filename $request_filename; fastcgi_param app_env dev; } sendfile off; }
server.js
var express = require('express'); var app = express(); var httpproxy = require('http-proxy'); var proxy = httpproxy.createproxyserver(); app.get('/', function (req, res) { console.log("test!!"); proxy.web(req, res, { target: 'http://127.0.0.1:80' }); //res.send('hello world!'); }); app.listen(3001);
with internal server error because in loop redirects me nginx node server , on.
any idea how can make node server running on my-project.com , not nginx?
i not sur (i begin nginx), don't add second configuration server 127.0.0.1 , localhost serve php ?
server { listen *:80; server_name 127.0.0.1 localhost; client_max_body_size 1m; root /var/www/public; index index.html index.htm index.php; access_log /var/log/nginx/nxv_5rxici0o7b9k.access.log; error_log /var/log/nginx/nxv_5rxici0o7b9k.error.log; location ~ \.php$ { root /var/www/public; fastcgi_index index.php; fastcgi_split_path_info ^(.+\.php)(/.*)$; try_files $uri $uri/ /index.php$is_args$args; include /etc/nginx/fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_param script_filename $request_filename; fastcgi_param app_env dev; } sendfile off; } server { listen *:80; server_name my-project.com www.my-project.com; client_max_body_size 1m; root /var/www/public; index index.html index.htm index.php; access_log /var/log/nginx/nxv_5rxici0o7b9k.access.log; error_log /var/log/nginx/nxv_5rxici0o7b9k.error.log; location / { proxy_pass http://localhost:3001; ### added line root /var/www/public; try_files $uri $uri/ /index.php$is_args$args; autoindex off; index index.html index.htm index.php; } location ~ \.php$ { root /var/www/public; fastcgi_index index.php; fastcgi_split_path_info ^(.+\.php)(/.*)$; try_files $uri $uri/ /index.php$is_args$args; include /etc/nginx/fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_param script_filename $request_filename; fastcgi_param app_env dev; } sendfile off; }
Comments
Post a Comment