我正在使用nginx和开发一个django驱动的应用程序gunicorn.一切都很好,直到今天我试图重新启动nginx失败.所以我用sudo nginx -t命令测试它,我得到了这个错误.
nginx: [emerg] host not found in "localhost:8004" of the "listen" directive in
/etc/nginx/sites-enabled/808:2
nginx: configuration file /etc/nginx/nginx.conf test failed
Run Code Online (Sandbox Code Playgroud)
这是808配置文件内容:
server {
listen localhost:8004;
error_log /var/www/html/burger808/error.log;
location / {
proxy_pass http://127.0.0.1:8005;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header X-Real-IP $remote_addr;
add_header P3P 'CP="ALL DSP COR PSAa PSDa OUR NOR ONL UNI COM NAV"';
}
location /static/ {
autoindex on;
alias /var/www/html/burger808/burger808/static/;
}
location /media/ {
autoindex on;
alias /var/www/html/burger808/burger808/media/;
} …Run Code Online (Sandbox Code Playgroud) 我有一个与 Nginx 重定向相关的问题,您可以在下面看到配置。我的目标是从https://example.com重定向到https://www.example.com
我几乎在stackoverflow中查看了所有内容,但没有找到任何帮助。请帮我解决这个问题。我将提供有关我的 Nginx Web 服务器的所有必要信息。我希望你能帮我解决这个难题。
我的文件nginx.conf看起来像那里:
user www-data;
worker_processes 4;
pid /run/nginx.pid;
events {
worker_connections 768;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
server_names_hash_bucket_size 64;
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
gzip on;
gzip_static on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 9;
# gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xm$
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
Run Code Online (Sandbox Code Playgroud)
我的档案 /etc/nginx/sites-enabled/example:
server { …Run Code Online (Sandbox Code Playgroud) 我在 DigitalOcean Ubuntu 16.04 Droplet 上有一个 Meteor 1.6 站点,使用 Phusion Passenger 和 Nginx 部署。
我已经在我的服务器上设置了 ssl。
http://mysite重定向到https://mysite并且该网站工作正常。
然而,http://www.mysite重定向到https://mysite并且显示的只是默认的 Nginx 页面“欢迎来到 nginx!”。
我已经按照教程并尝试了其他论坛帖子中的内容,但我找不到我的设置有什么问题。
来自 DigitalOcean 控制面板的 DNS 记录:
A www.mysite.org directs to xxx.xx.xx.xx 3600
A mysite.org directs to xxx.xx.xx.xx 1800
Run Code Online (Sandbox Code Playgroud)
然后,我按照本教程使用 Certbot 和 LetsEncrypt 配置 ssl: https://www.digitalocean.com/community/tutorials/how-to-set-up-let-s-encrypt-with-nginx-server-blocks-on- ubuntu-16-04
我添加了一个服务器块,按照本教程将 www 重定向到普通域:https: //www.digitalocean.com/community/tutorials/how-to-redirect-www-to-non-www-with-nginx-在 ubuntu-14-04 上
这是我的 nginx 配置:
sudo nano /etc/nginx/sites-enabled/mysite.conf
server {
server_name mysite.org www.mysite.org;
...Meteor app config
# added by Certbot
listen 443 …Run Code Online (Sandbox Code Playgroud)