如何使用nginx配置express子目录?

时间:2015-06-21 07:05:39

标签: node.js express nginx

我是Nginx的新手。 我正在使用-编写一个Web应用程序,该项目位于目录Express中,这是项目结构。

/home/ubuntu/wangqiuke

这是我的Nginx配置:

ubuntu@VM-165-36-ubuntu:~/wangqiuke$ ls -l
total 36
-rw-rw-r--  1 ubuntu ubuntu 1958 Jun 14 15:08 app.js
drwxr-xr-x  2 ubuntu ubuntu 4096 Jun 21 12:39 bin
drwxrwxr-x  2 ubuntu ubuntu 4096 Jun 15 16:37 config
drwxrwxr-x  2 ubuntu ubuntu 4096 Jun 12 14:42 models
drwxrwxr-x 19 ubuntu ubuntu 4096 Jun 14 14:55 node_modules
-rw-rw-r--  1 ubuntu ubuntu  588 Jun 14 14:55 package.json
drwxr-xr-x  5 ubuntu ubuntu 4096 Jun  6 09:44 public
drwxr-xr-x  2 ubuntu ubuntu 4096 Jun 15 16:40 routes
drwxr-xr-x  2 ubuntu ubuntu 4096 Jun  6 09:44 views

当我访问此页面 user www-data; worker_processes 4; pid /run/nginx.pid; events { worker_connections 768; # multi_accept on; } http { ## # Basic Settings ## server_names_hash_bucket_size 128; server { listen 80; listen 443 ssl; server_name www.darenwu.me darenwu.me; ssl_certificate /home/ubuntu/wangqiuke/config/hacksparrow-cert.pem; ssl_certificate_key /home/ubuntu/wangqiuke/config/hacksparrow-key.pem; 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; if ($host = 'darenwu.me') { rewrite ^/(.*)$ http://www.darenwu.me/$1 permanent; } location ~ ^/(images/|img/|javascript/|js/|css/|stylesheets/|flash/|media/|static/|robots.txt|humans.txt|favicon.ico) { root /home/ubuntu/wangqiuke/public; access_log off; expires max; } location /wangqiuke { proxy_pass http://localhost:8080; rewrite /wangqiuke(.*) /$1 break; proxy_set_header Host $host; proxy_redirect off; proxy_set_header Host $proxy_host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; # server_tokens off; # server_names_hash_bucket_size 64; # server_name_in_redirect off; include /etc/nginx/mime.types; default_type application/octet-stream; ## # Logging Settings ## access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; ## # Gzip Settings ## gzip on; gzip_disable "msie6"; # gzip_vary on; # gzip_proxied any; # gzip_comp_level 6; # gzip_buffers 16 8k; # gzip_http_version 1.1; # gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript; ## # nginx-naxsi config ## # Uncomment it if you installed nginx-naxsi ## #include /etc/nginx/naxsi_core.rules; ## # nginx-passenger config ## # Uncomment it if you installed nginx-passenger ## #passenger_root /usr; #passenger_ruby /usr/bin/ruby; ## # Virtual Host Configs ## include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; } 时,一切正常:

http://www.darenwu.me/wangqiuke

但资产文件错误:

    Request URL:http://www.darenwu.me/wangqiuke
    Request Method:GET
    Status Code:200 OK

    Response Headers
    Connection:keep-alive
    Content-Encoding:gzip
    Content-Type:text/html; charset=utf-8
    Date:Sun, 21 Jun 2015 06:58:47 GMT
    Server:nginx/1.4.6 (Ubuntu)
    Transfer-Encoding:chunked
    X-Powered-By:Express

    Request Headers
 Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
    Accept-Encoding:gzip, deflate, sdch
    Accept-Language:en-US,en;q=0.8,zh-CN;q=0.6,zh;q=0.4
    Cache-Control:no-cache
    Connection:keep-alive
    Cookie:connect.sid=s%3AF3m36gHkr5eMV0c8-LCpzQRJDDIdbf2m.UY1bqEYNILPY0c7UIQMLH9Nw4m9OgfzoHgsQ3YenQyQ
    Host:www.darenwu.me
    Pragma:no-cache
    User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.152 Safari/537.36

响应标头

Request URL:http://www.darenwu.me/stylesheets/style.css
Request Method:GET
Status Code:200 OK

请求标题

Accept-Ranges:bytes
Cache-Control:max-age=315360000
Connection:keep-alive
Content-Length:110
Content-Type:text/css
Date:Sun, 21 Jun 2015 06:58:47 GMT
ETag:"5572507a-6e"
Expires:Thu, 31 Dec 2037 23:55:55 GMT
Last-Modified:Sat, 06 Jun 2015 01:44:26 GMT
Server:nginx/1.4.6 (Ubuntu)

我认为请求网址(Accept:text/css,*/*;q=0.1 Accept-Encoding:gzip, deflate, sdch Accept-Language:en-US,en;q=0.8,zh-CN;q=0.6,zh;q=0.4 Cache-Control:no-cache Connection:keep-alive Cookie:connect.sid=s%3AF3m36gHkr5eMV0c8-LCpzQRJDDIdbf2m.UY1bqEYNILPY0c7UIQMLH9Nw4m9OgfzoHgsQ3YenQyQ Host:www.darenwu.me Pragma:no-cache Referer:http://www.darenwu.me/wangqiuke User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.152 Safari/537.36 )有误,应该是Request URL:http://www.darenwu.me/stylesheets/style.css

如何在NGINX中配置?

0 个答案:

没有答案