运行 Apache2 服务器和节点服务器 [NGINX]
Running Apache2 Server along with Node Server [NGINX]
我有一台安装了多个 node.Js 应用程序的服务器。我按照本指南设置我的反向代理设置:https://www.digitalocean.com/community/tutorials/how-to-host-multiple-node-js-applications-on-a-single-vps-with-nginx-forever-and-crontab
所以我的 /etc/nginx/conf.d
文件夹里塞满了 Nginx 配置文件,例如:
server {
listen 80;
server_name my-domain.com;
location / {
proxy_pass http://localhost:3001; // my node app runs on port 3001
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;
}
}
然后,我在端口 3002 上安装并设法 运行 我的 apache2
服务器。我尝试使用此配置:
server {
listen 80;
server_name my-wordpress-blog.com;
location / {
proxy_pass http://localhost:3002/wordpress-folder-name; // yes, this is for wordpress
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;
}
}
问题是:每当我尝试访问 my-wordpress-blog.com
时,它都会将我重新路由到 my-wordpress-blog.com/html
并出现 404 错误:The requested URL /htmlhtml/ was not found on this server..
那么如何正确设置呢?谢谢
正如您为我自己的 wordpress 安装请求我的配置脚本一样。它基于 Debian 提供的默认 nginx 和 php5-fpm 包。不确定它是否是最佳配置,因为它很旧,但它可以工作 ;)
/etc/nginx/sites-enabled/my-site.conf
# Upstream to abstract backend connection(s) for php
upstream php {
server unix:/tmp/php-cgi.socket;
#server 127.0.0.1:9000;
}
server {
## Your website name goes here.
server_name example.com;
## Your only path reference.
root /var/www/your-wp-installation;
## This should be in your http block and if it is, it's not needed here.
index index.php;
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location / {
# This is cool because no php is touched for static content
try_files $uri $uri/ /index.php;
}
location ~ \.php$ {
#NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
include fastcgi.conf;
fastcgi_intercept_errors on;
fastcgi_pass php;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}
}
我还包含 fastcgi.conf 文件,但我认为它是默认文件
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param HTTPS $https if_not_empty;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;
我有一台安装了多个 node.Js 应用程序的服务器。我按照本指南设置我的反向代理设置:https://www.digitalocean.com/community/tutorials/how-to-host-multiple-node-js-applications-on-a-single-vps-with-nginx-forever-and-crontab
所以我的 /etc/nginx/conf.d
文件夹里塞满了 Nginx 配置文件,例如:
server {
listen 80;
server_name my-domain.com;
location / {
proxy_pass http://localhost:3001; // my node app runs on port 3001
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;
}
}
然后,我在端口 3002 上安装并设法 运行 我的 apache2
服务器。我尝试使用此配置:
server {
listen 80;
server_name my-wordpress-blog.com;
location / {
proxy_pass http://localhost:3002/wordpress-folder-name; // yes, this is for wordpress
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;
}
}
问题是:每当我尝试访问 my-wordpress-blog.com
时,它都会将我重新路由到 my-wordpress-blog.com/html
并出现 404 错误:The requested URL /htmlhtml/ was not found on this server..
那么如何正确设置呢?谢谢
正如您为我自己的 wordpress 安装请求我的配置脚本一样。它基于 Debian 提供的默认 nginx 和 php5-fpm 包。不确定它是否是最佳配置,因为它很旧,但它可以工作 ;)
/etc/nginx/sites-enabled/my-site.conf
# Upstream to abstract backend connection(s) for php
upstream php {
server unix:/tmp/php-cgi.socket;
#server 127.0.0.1:9000;
}
server {
## Your website name goes here.
server_name example.com;
## Your only path reference.
root /var/www/your-wp-installation;
## This should be in your http block and if it is, it's not needed here.
index index.php;
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location / {
# This is cool because no php is touched for static content
try_files $uri $uri/ /index.php;
}
location ~ \.php$ {
#NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
include fastcgi.conf;
fastcgi_intercept_errors on;
fastcgi_pass php;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}
}
我还包含 fastcgi.conf 文件,但我认为它是默认文件
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param HTTPS $https if_not_empty;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;