我想在运行nginx和node.js的localhost上运行2个不同的网站,因为我已经写了nginx文件。
位点可用/默认
upstream app_site1 {
server 127.0.0.1:3001;
keepalive 80;
}
upstream app_site2 {
server 127.0.0.1:3002;
}
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /home/user/workspace/site1;
index index.html index.htm;
# Make site accessible from http://localhost/
server_name localhost;
access_log /dev/null;
#error_log /var/log/stat-error.log;
# static resources
location ~ ^/(robots.txt|humans.txt|favicon.ico) {
root /home/user/workspace/statistics;
access_log on;
expires max;
}
location = /favicon.ico {
root /home/user/workspace;
log_not_found off;
}
location ~ /js/(.*) {
add_header X-debug-message "A static file was served by pushstate";
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass http://app_stat;
}
location ~ /socket.io/(.*) {
add_header X-debug-message "A static file was served by pushstate";
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass http://app_stat;
}
location ~ ^/(.+?)(/.*)?$ {
add_header X-debug-message "A static file was served by pushstate";
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass http://app_stat;
}
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
# try_files $uri $uri/ =404;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
if ($http_user_agent ~ (Googlebot|google|bing|yandex|msnbot|AltaVista|DuckDuckBot) ) {
return 403;
}
add_header X-debug-message $http_accept;
# break;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass http://app_stat;
}
}
# another virtual host using mix of IP-, name-, and port-based configuration
server {
listen 3002;
#listen [::]:3002 ipv6only=on;
root /home/user/workspace/site2/;
#index index.html;
server_name 192.168.1.201;
fastcgi_intercept_errors on;
# static resources
location ~ ^/(robots.txt|humans.txt|favicon.ico) {
root /home/user/workspace/site2/;
access_log on;
expires max;
}
location / {
# First attempt to serve request as file, then as directory, then fall back to displaying a 404.
# try_files $uri $uri/ =404;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
if ($http_user_agent ~ (Googlebot|google|bing|yandex|msnbot|AltaVista|DuckDuckBot) ) {
return 403;
}
try_files $uri $uri/ /public/index.html$request_uri;
#index index.html;
add_header X-debug-message $http_accept;
# break;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
#proxy_pass http://app_site2;
}
}
但它告诉我:
rewrite or internal redirection cycle while internally redirecting to "/public/index.html/css/login.css"
我的应用程序中的文件夹结构
site2
node_modules
public
html
css
js
....
....
app.js
package.json
index.html
的index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Login</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<link href='http://fonts.googleapis.com/css?family=Open+Sans:400,600' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="css/login.css">
<script src="js/jquery-1.10.2.min.js"></script>
<script src="js/index.js"></script>
</head>
<body>
<section class="center">
<input id='username' type="username" placeholder="Username">
<input id='password' type="password" placeholder="Password">
</section>
</body>
</html>
我已经提到过css&amp; amp;脚本是&#34; css&#34; &安培; &#34; JS&#34;公共文件夹,但在nginx错误日志中,它显示我&#34; /public/index.html/css/login.css"。为什么它包含index.html作为文件夹?我的mistek在哪里?我是nginx的新手。
由于