gpt4 book ai didi

node.js - 使用 SSL 配置 Nginx 后 Meteor 应用程序无法运行

转载 作者:太空宇宙 更新时间:2023-11-03 21:55:00 32 4
gpt4 key购买 nike

我已经部署了一个 Meteor 应用程序,其中 Passenger 与 Nginx 集成(以下 this documentation )。除非我使用 Lets Encrypt 配置 Nginx for SSL,否则该应用程序运行良好。关注this documentation

应用 SSL 后,访问应用程序会显示带有 https 的 nginx 欢迎页面。

我尝试过:
已删除root /var/www/html; ,替换root <meteor directory>/bundle/programs/webserver;

谁能告诉我如何将我的域指向已部署的 meteor 应用程序?

我的/etc/nginx/sites-enable/default文件看起来像:

server {
listen 80 ;
listen [::]:80;

# SSL configuration
listen 443 ssl;
listen [::]:443 ssl;

server_name example.com;

#return 301 https://$server_name$request_uri;

include snippets/ssl-example.com.conf;
include snippets/ssl-params.conf;


location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}

location ~ /.well-known {
allow all;
}
}

还有/etc/nginx/example.conf如下所示:

server {
listen 80;
server_name example.com;

# Tell Nginx and Passenger where your app's 'public' directory is
root /var/www/example/bundle/public;

# Turn on Passenger
passenger_enabled on;
# Tell Passenger that your app is a Meteor app
passenger_app_type node;
passenger_startup_file main.js;

# Tell your app where MongoDB is
passenger_env_var MONGO_URL mongodb://<user>:<password@<host>:<port>/dbName;
passenger_env_var ROOT_URL http://example.com;
}

这是 nginx 的确切配置( nginx -T )

nginx: [warn] conflicting server name "example.com" on 0.0.0.0:80, ignored
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
# configuration file /etc/nginx/nginx.conf:
user www-data;
worker_processes auto;
pid /run/nginx.pid;

events {
worker_connections 768;
# multi_accept on;
}

http {

##
# Basic Settings
##

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;

##
# SSL Settings
##

ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;

##
# 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/javascript text/xml application/xml application/xml+rss text/javascript;

##
# Phusion Passenger config
##
# Uncomment it if you installed passenger or passenger-enterprise
##

include /etc/nginx/passenger.conf;

##
# Virtual Host Configs
##

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}

# configuration file /etc/nginx/mime.types:

types {
text/html html htm shtml;
text/css css;
text/xml xml;
image/gif gif;
image/jpeg jpeg jpg;
application/javascript js;
application/atom+xml atom;
application/rss+xml rss;

text/mathml mml;
text/plain txt;
text/vnd.sun.j2me.app-descriptor jad;
text/vnd.wap.wml wml;
text/x-component htc;

image/png png;
image/tiff tif tiff;
image/vnd.wap.wbmp wbmp;
image/x-icon ico;
image/x-jng jng;
image/x-ms-bmp bmp;
image/svg+xml svg svgz;
image/webp webp;

application/font-woff woff;
application/java-archive jar war ear;
application/json json;
application/mac-binhex40 hqx;
application/msword doc;
application/pdf pdf;
application/postscript ps eps ai;
application/rtf rtf;
application/vnd.apple.mpegurl m3u8;
application/vnd.ms-excel xls;
application/vnd.ms-fontobject eot;
application/vnd.ms-powerpoint ppt;
application/vnd.wap.wmlc wmlc;
application/vnd.google-earth.kml+xml kml;
application/vnd.google-earth.kmz kmz;
application/x-7z-compressed 7z;
application/x-cocoa cco;
application/x-java-archive-diff jardiff;
application/x-java-jnlp-file jnlp;
application/x-makeself run;
application/x-perl pl pm;
application/x-pilot prc pdb;
application/x-rar-compressed rar;
application/x-redhat-package-manager rpm;
application/x-sea sea;
application/x-shockwave-flash swf;
application/x-stuffit sit;
application/x-tcl tcl tk;
application/x-x509-ca-cert der pem crt;
application/x-xpinstall xpi;
application/xhtml+xml xhtml;
application/xspf+xml xspf;
application/zip zip;

application/octet-stream bin exe dll;
application/octet-stream deb;
application/octet-stream dmg;
application/octet-stream iso img;
application/octet-stream msi msp msm;

application/vnd.openxmlformats-officedocument.wordprocessingml.document docx;
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet xlsx;
application/vnd.openxmlformats-officedocument.presentationml.presentation pptx;

audio/midi mid midi kar;
audio/mpeg mp3;
audio/ogg ogg;
audio/x-m4a m4a;
audio/x-realaudio ra;

video/3gpp 3gpp 3gp;
video/mp2t ts;
video/mp4 mp4;
video/mpeg mpeg mpg;
video/quicktime mov;
video/webm webm;
video/x-flv flv;
video/x-m4v m4v;
video/x-mng mng;
video/x-ms-asf asx asf;
video/x-ms-wmv wmv;
video/x-msvideo avi;
}

# configuration file /etc/nginx/passenger.conf:
passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
passenger_ruby /usr/bin/passenger_free_ruby;

# configuration file /etc/nginx/sites-enabled/default:
##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# http://wiki.nginx.org/Pitfalls
# http://wiki.nginx.org/QuickStart
# http://wiki.nginx.org/Configuration
#
# Generally, you will want to move this file somewhere, and start with a clean
# file but keep this around for reference. Or just disable in sites-enabled.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##

# Default server configuration
#
server {
listen 80 ;
listen [::]:80;

# SSL configuration
listen 443 ssl;
listen [::]:443 ssl;


# Add index.php to the list if you are using PHP
#index index.html index.htm index.nginx-debian.html;

server_name example.com;

#return 301 https://$server_name$request_uri;

include snippets/ssl-example.com.conf;
include snippets/ssl-params.conf;


location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}

location ~ /.well-known {
allow all;
}
}

# configuration file /etc/nginx/snippets/ssl-example.com.conf:
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;

# configuration file /etc/nginx/snippets/ssl-params.conf:
# from https://cipherli.st/
# and https://raymii.org/s/tutorials/Strong_SSL_Security_On_nginx.html

ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH";
ssl_ecdh_curve secp384r1;
ssl_session_cache shared:SSL:10m;
ssl_session_tickets off;
ssl_stapling on;
ssl_stapling_verify on;
resolver 8.8.8.8 8.8.4.4 valid=300s;
resolver_timeout 5s;
# Disable preloading HSTS for now. You can use the commented out header line that includes
# the "preload" directive if you understand the implications.
#add_header Strict-Transport-Security "max-age=63072000; includeSubdomains; preload";
add_header Strict-Transport-Security "max-age=63072000; includeSubdomains";
add_header X-Frame-Options DENY;
add_header X-Content-Type-Options nosniff;

ssl_dhparam /etc/ssl/certs/dhparam.pem;


# configuration file /etc/nginx/sites-enabled/example.conf:
server {
listen 80;
server_name example.com;

# Tell Nginx and Passenger where your app's 'public' directory is
root /var/www/example/bundle/public;

# Turn on Passenger
passenger_enabled on;
# Tell Passenger that your app is a Meteor app
passenger_app_type node;
passenger_startup_file main.js;

# Tell your app where MongoDB is
passenger_env_var MONGO_URL connection_string;
# Tell your app what its root URL is
passenger_env_var ROOT_URL http://example.com;
#passenger_env_var ROOT_URL http://www.example.com;
}

最佳答案

问题是,一个教程告诉您编辑 default,另一个教程告诉您创建 example.conf

事实上,它们都引用同一个文件,并且您所说的内容无关紧要。

目前,您的配置分为两个文件,其中有两个 server_name example.com;,这令人困惑 nginx

决定使用哪个文件名,并删除另一个。将乘客和 Let's Encrypt 配置合并到一个文件中。

例如:

server {
listen 80 ;
listen [::]:80;

# SSL configuration
listen 443 ssl;
listen [::]:443 ssl;

server_name example.com;

include snippets/ssl-example.com.conf;
include snippets/ssl-params.conf;

location ~ /.well-known {
root /path/to/ssl/bits;
allow all;
}

root /var/www/example/bundle/public;
...
}

关于node.js - 使用 SSL 配置 Nginx 后 Meteor 应用程序无法运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43427546/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com