我似乎找不到足够的文档。我有一个生成一些动态响应的应用程序,但仍然可以从Last-Modified标题中受益——所以我发送了它。
但是,打开if_modified_since(设置为before,根据http://nginx.org/en/docs/http/ngx_http_core_module.html#if_modified_since)似乎对非静态资源没有任何影响。例如,php、python 应用程序。
这是因为 Nginx 不只是查看我的响应Last-Modified标头吗?因为我可以看到它们似乎设置正确,如下所示:
> GET /3.0/view.json?id=2 HTTP/1.1
> Host: xxxxxxxxxxxxx
> Accept: */*
> If-Modified-Since: Sat, 02 May 2015 19:43:02 GMT
>
< HTTP/1.1 200 OK
* Server nginx/1.4.7 is not blacklisted
< Server: nginx/1.4.7
< Date: Fri, 01 May 2015 19:56:05 GMT
< Content-Type: application/json; charset=utf-8
< Transfer-Encoding: chunked
< Connection: keep-alive
< Vary: Accept-Encoding
< Last-Modified: Fri, 01 May 2015 19:56:05 GMT
Run Code Online (Sandbox Code Playgroud)
或者我忽略了更大的东西?只是好奇是如何 …
我需要通过删除一部分 url 将一些请求传递给代理(运行 GlassFish)。例如:
https://xxx.net/jazz/MobileApi?id=2&make_id=4
Run Code Online (Sandbox Code Playgroud)
应该传递给代理:
http://X.X.X.X:8080/MobileApi?id=2&make_id=4
Run Code Online (Sandbox Code Playgroud)
我有以下 Nginx 配置:
upstream vito_api {
server 178.63.X.X:8080;
}
server {
listen 80;
listen 443 ssl;
....
location ~ /jazz/(?<section>.*) {
proxy_pass http://vito_api/$section/;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
Run Code Online (Sandbox Code Playgroud)
但是,不幸的是,请求不带参数传递。因此,在 GlassFish 访问日志中,我只能看到:
"148.251.X.X" "NULL-AUTH-USER" "05/Jan/2015:15:18:40 +0100" "GET /MobileApi/ HTTP/1.0" 200 21
Run Code Online (Sandbox Code Playgroud)
我做错了什么?如何传递URL参数?
谢谢你。
我在 vmware-esxi 虚拟化中使用 debian 7 x64。
每个客户端的最大下载速度为 1mb/s,而 nginx 一起使用的速度不超过 50mbps,我的问题是什么可能导致如此缓慢的传输?
**Settings for eth1:
Supported ports: [ TP ]
Supported link modes: 1000baseT/Full
10000baseT/Full**
root@www:~# iostat
Linux 3.2.0-4-amd64 (www) 09.02.2015 _x86_64_ (4 CPU)
avg-cpu: %user %nice %system %iowait %steal %idle
1,75 0,00 0,76 0,64 0,00 96,84
Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn
sda 173,93 1736,11 219,06 354600 44744
root@www:~# free -m
total used free shared buffers cached
Mem: 12048 1047 11000 0 106 442
-/+ buffers/cache: 498 11549
Swap: …Run Code Online (Sandbox Code Playgroud) 我有a.b域(例如)并希望username.github.io/project在a.b/c. 这意味着我还想将我的浏览器 url 保留a.b/c为username.github.io/project.
我在 nginx 模块中有以下设置
location /c {
proxy_pass http://username.github.io/project;
proxy_redirect http://username.github.io http://a.b;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_buffering off;
}
Run Code Online (Sandbox Code Playgroud)
如果我更改proxy_set_header Host $http_host为proxy_set_header Host $proxy_hostor $host,它只是重定向到http://username.github.io/project我不想要的。我能怎么做?
我编写了一些脚本,并希望在known_hosts没有任何交互的情况下将远程主机添加到我的文件中。我可以运行类似的命令ssh -o "StrictHostKeyChecking no" root@10.x.x.x,将远程主机密钥添加到我的已知主机,但后面会出现 ssh 密码提示。在没有密码提示的情况下有什么方法可以做到这一点?
我正在尝试使用反向代理访问另一个服务器后面的服务器。“主”服务器位于 mydomain.com 后面,我想使用 mydomain.com/test 访问第二个服务器。目前只有 mydomain.com/test 有效。
但是,如果我尝试访问 mydomain.com/test/myfiles,我将被重定向到不存在的 mydomain.com/myfiles,因为此 url 以“主”服务器为目标,因此出现 404 not found。我用proxy_redirect尝试了多种方法,重写但没有任何效果。
server {
listen 80;
index index.php index.html index.htm;
root /path/to/content;
server_name localhost mydomain.com;
location / {
try_files $uri $uri/ =404; #/index.html;
}
location /test/ {
proxy_pass http://192.168.1.202/;
proxy_set_header Host $host;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
Run Code Online (Sandbox Code Playgroud)
curl -I "http://192.168.1.202" -H "Host: mydomain.com" 在主服务器上给出:
HTTP/1.1 301 Moved Permanently
Server: nginx/1.2.1
Date: Sun, 02 Nov 2014 15:02:56 GMT
Content-Type: text/html …Run Code Online (Sandbox Code Playgroud) 伙计们!:-) 。
关于我的 iptables 设置,我需要你的(几个?)建议。我对 iptables 很陌生,这是我第一次使用 iptables 配置服务器作为防火墙(我们没有钱也没有时间预先设置“真正的”防火墙)。
我想通过 SSH 仅从 specific.location.com 连接到我的服务器。
因此,我在 INPUT 中设置了以下规则:
target in out source destination
ACCEPT lo any localhost anywhere
ACCEPT any any specific.location.com myserver.local tcp dpt:ssh
Run Code Online (Sandbox Code Playgroud)
我的默认政策是:
INPUT DROP
FORWARD DROP
OUTPUT ACCEPT
Run Code Online (Sandbox Code Playgroud)
使用第一个配置,我能够连接到我的服务器,但无法访问外部(如 google.com),并且连接速度非常慢。
我知道我的防火墙没有任何规则,包括来自数据包的“ESTABLISHED”状态。确实,我猜我的包能够出去,但不允许回来......
所以我添加了这个规则:
target in out source destination
ACCEPT any any anywhere anywhere state ESTABLISHED
Run Code Online (Sandbox Code Playgroud)
现在一切都像魅力一样,我可以从服务器外部访问,连接像以前一样非常快,而且我只能从 specific.location.com 以 SSH 访问我的服务器!
我唯一的问题是我需要你的建议,这是一个干净的配置吗?我在互联网上没有找到任何这样的例子,所以我很想知道......
还是我只是犯了一个巨大的安全错误?!
谢谢你们的帮助:-)
我有一个在域(例如 example.com)上运行的基本 html 站点,我想在子目录(例如:example.com/test)中运行一个flask应用程序,flask应用程序使用默认的flask开发在端口5433上运行服务器。
我使用以下 nginx 配置来实现这一点
location /test {
rewrite /test(.*) $1 break;
proxy_pass http://localhost:5433;
proxy_redirect default;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /static/{
alias /home/hrishi/www/example.com/test/app/static/;
}
Run Code Online (Sandbox Code Playgroud)
我可以使用 example.com/test/ url 访问该应用程序,但尽管有别名,静态文件仍无法加载(给出 404 错误)。
我怎样才能解决这个问题?
更新:按照说明添加整个服务器块
server {
listen *:80 default_server; ## listen for ipv4; this line is default and implied
#listen [::]:80; # listen for ipv6
root /home/hrishi/www/example.com/;
index index.php index.html index.htm;
# Make site accessible from http://localhost/
server_name example.com;
# Logging
access_log …Run Code Online (Sandbox Code Playgroud) 出于某种原因,我无法更改根目录。我与 上的默认根目录具有相同的权限/usr/share/nginx/html,并且我还755对其他文件夹中的所有文件和文件夹具有递归权限。我什至尝试将用户和组来回更改为 root 和 nginx,看看它是否有任何区别,但没有。我不断收到403 Forbidden
所以基本上我做了这个文件夹
$ mkdir -p /srv/www/test.com/public_html
$ vi /srv/www/test.com/public_html/index.html
$ vi /srv/www/test.com/public_html/test.php
$ chmod -R 755 /srv/www/test.com/public_html
Run Code Online (Sandbox Code Playgroud)
尝试将用户和组更改为 nginx
$ chown -R nginx:nginx /srv/www
Run Code Online (Sandbox Code Playgroud)
配置主conf文件
$ vi /etc/nginx/nginx.conf
Run Code Online (Sandbox Code Playgroud)
这是我的配置的样子,包含被注释掉
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
keepalive_timeout 65;
index …Run Code Online (Sandbox Code Playgroud) nginx ×7
linux ×3
networking ×2
cache ×1
centos ×1
debian ×1
flask ×1
http-headers ×1
iptables ×1
known-hosts ×1
proxy ×1
proxypass ×1
redirect ×1
rules ×1
security ×1
ssh ×1
ssh-keys ×1
vmware-esxi ×1