我正在将一个由别人写的php应用程序从apache转换到nginx。 开发人员在.htaccess中有这个 <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-s RewriteRule ^(.*)$ api.php?rquest=$1 [QSA,NC,L] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^(.*)$ api.php [QSA,NC,L] RewriteCond %{REQUEST_FILENAME} -s RewriteRule ^(.*)$ api.php [QSA,NC,L] </IfModule> 我简单地读了这个 “如果文件/目录不存在,请将请求重写为api.php?rquest = $ uri” “如果文件/目录确实存在,请将该请求重写为api.php” 我试图在nginx中复制这个,但遇到问题。 我创build了一个位置指令 location / { # if the file or folder doesn't exist add it as arguments to […]
我configuration了nginx的端口转发(端口80到8889) 并指出我的域名服务器的IP地址。 之后它成功地将我redirect到服务器。 当我尝试通过域地址访问url 但redirect后,我只能看到IP而不是我的url(即mydomain.com)在地址栏(即xx.xx.xx.xx:8889),我需要做的,如果我想在地址栏中显示域? 这是我的nginxconfiguration文件。 server { listen 80; server_name mywebsite.com 172.10.19.14; server_name proxy_connect_timeout 300; proxy_send_timeout 300; proxy_read_timeout 300; send_timeout 300; location / { proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_pass http://localhost:8888/; } client_max_body_size 10M; error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html […]
我有一个问题在我的nginx上logging一个自定义的proxy_set_header。 我有nginx作为反向代理位于同一个服务器(用于testing)的apache服务器。 这个名为“xreqid”的头文件充当每个事务的唯一ID,并设置为各种variables,如$ pid $ msec。 这个头文件是使用proxy_set_header创build的,以便在后端服务器上传递。 而且,标题的内容首先被“设置”为随后用于标题“xreqid”的variables名“reqid” nginx的前端configuration很简单: server { listen 80 default_server; root /var/www/html; index index.html index.htm index.nginx-debian.html; server_name _; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; set $reqid $pid-$msec-$remote_addr-$request_length; proxy_set_header xreqid $reqid; location / { proxy_pass http://localhost:8080/; try_files $uri $uri/ =404; } # Log formating access_log /var/log/nginx/unified.access.log my_log_format; 和日志格式: log_format my_log_format '$hostname "$http_user_agent" […]
我一直在研究这个问题太久,所以我需要来请求专家的帮助! 我的查询是非常类似于这里问: nginx代理传递redirect忽略端口,但我相信,我的节点应用程序的行为略有不同。 我正在运行Intel AMT NodeJS应用程序meshcommander( http://www.meshcommander.com/meshcommander ),它在端口3000上提供一个web应用程序。该应用程序在服务器192.168.0.27上运行。 我的nginx服务器在端口80上的同一台服务器上运行,这就是我在主服务器块下设置了反向代理的方式: location /intel { satisfy any; allow 192.168.0.0/24; deny all; auth_basic "Restricted Content"; auth_basic_user_file /etc/nginx/.htpasswd; rewrite /intel(/.*) /$1 break; proxy_pass http://192.168.0.27:3000; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $http_host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } 我遇到的第一个问题是,当你直接在端口3000上打开节点应用程序时,像这样: http://192.168.0.27:3000 它会redirect到另一个页面: http://192.168.0.27:3000/default.htm 不幸的是,当你转到:nginx反向代理不会自动发生这种情况: http://192.168.0.27/intel 但没有问题,这只是为了调用这个方法: htt://192.168.0.27/intel/default.htm 这很好,但是在使用web应用程序时,最终需要调用局域网上的另一台服务器,以及发生故障的地方。 我可以看到节点应用程序中的某些操作调用页面,如: http://192.168.0.27/intel/webrelay.ashx?p=1&host=10.7.7.6&port=16992&tls=0 它返回一个404,我可以看到这是它被发送的方式: Request URL:http://192.168.0.27/intel/webrelay.ashx?p=1&host=10.7.7.6&port=16992&tls=0 Request method:GET […]
我是代理传递使用Nginxcaching的服务,我想刷新每个请求,甚至caching的date头。 有没有办法做到这一点? 我已经看到了add_header指令,但我不知道如何问NginX它将其设置为当前date。
这是我的nginx / 1.10.3中的一个位置块 location ~* ^/(.*)/announced$ { rewrite ^ /announcement/$1 redirect; } 但每次我不断redirect到/公告,但variables$ 1丢失 我甚至试过这个 location ~* ^/.*/announced$ { rewrite ^/(.*)/announced /$1/announcement redirect; } 但仍然不起作用。
我在cron中有一个任务: sudo /usr/local/bin/certbot renew –quiet 它失败。 在停止nginx并重新运行命令后,它成功。 然后我必须再次启动nginx。 不过,我不想停止它,因为cron任务每天执行一次,自动停止nginx将使我的网站不可用。 如何避免停止nginx?
我正在寻找在Nginx上设置现金,因此某些文件的caching永远不会超过2个小时,而且caching将在每天早上6点15分过期。 我遇到的问题是在相同的位置块中设置这两个时间限制。 到目前为止,我有这个 uwsgi_cache_path /data/nginx_cache levels=1:2 keys_zone=my_cache:10m max_size=10g; . . . location ~* /my/path/and/image.*\.png$ { expires 7200; include uwsgi_params; uwsgi_pass unix:/tmp/my_project_name.sock; uwsgi_cache_key $request_uri; uwsgi_cache my_cache; add_header Pragma public; add_header Cache-Control "public"; add_header X-Cache-Status $upstream_cache_status; } 我查看了http://nginx.org/en/docs/http/ngx_http_headers_module.html哪些设置caching过期使用expires @15h30m; 所以我试着设置 expires 7200, @6h15m; 但是这个语法似乎不被接受。 注意:另外,我还需要让用户的浏览器caching每30分钟左右过期一次。
我尝试设置Nginx + Gunicorn ,当我通过URL访问时, Nginx将请求redirect到我的应用程序,并通过itsels处理静态资源( static文件夹)。 在我的Nginx域configuration下面: server { listen 80; server_name asknow.local www.asknow.local; root /home/ghostman/Projects/asknow/asknow; location = /favicon.ico { access_log off; log_not_found off; } location = /static/ { root /home/ghostman/Projects/asknow/asknow; } location = / { include proxy_params; proxy_pass http://unix:/home/ghostman/Projects/asknow/asknow/asknow.sock; } } 我需要Nginx自己处理请求的问题( www.asknow.local/static ),但它也尝试处理其他URL。 所以当我现在去www.asknow.local/admin Nginx会尝试通过path( my_project/admin )来查找资源。 Nginx日志 2017/11/01 04:27:22 [error] 13451#13451: *1 […]
我正在尝试在Linode服务器上configurationnodejs,socket.io和nginx。 为此,我创build了虚拟主机。 在nginx.conf # Add to nginx.conf http section map $http_upgrade $connection_upgrade { default upgrade; '' close; } 在socket.example.com upstream some_upsteram_com { server 127.0.0.1:8888; keepalive 15; } server { listen 80; root /var/www/node-socket-app; index index.html index.htm; access_log /home/user/logs/socket-access.log; error_log /home/user/logs/socket-error.log; server_name socket.example.com; large_client_header_buffers 8 32k; location / { try_files $uri @nodejs; } # Important! Serve […]