最近在研究學習nginx,買了騰訊雲服務器、在阿里上申請了域名,部署項目遇到不少問題記錄一下,以備後用:javascript
1.在騰訊服務器買好(若是登陸密碼不知道能夠重置),阿里域名申請好後(也能夠在騰訊上申請域名),須要添加安全組,建立不一樣的規則,在入站規則中添加各個須要的TCP端口,具體建立方式自行百度。php
2.登陸到阿里域名後申請域名解析,添加網址解析記錄,設置@、www等,添加對應項目的端口。css
3.在服務器上部署好項目,安裝nginx,將loopback項目部署。安裝命令:java
sudo apt-get install nginx node
4.nginx基本操做命令nginx
5.若是登陸默認用戶時,建立文件的權限不夠,能夠執行命令將文件變成當前用戶私有文件:json
sudo chown -R 組名(隨便寫):用戶名 文件夾/安全
重啓:sudo service nginx restart服務器
修改配置文件:vi /etc/nginx/nginx.conf,這個是關鍵問題,搞了很久,附上個人配置文件:restful
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;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
server{ listen 80; server_name www.xxxxx.com xxxxx.com; location /restful { # proxy_pass http://nxweiqi; # root /; proxy_redirect off; proxy_set_header Host $host; #請求主機頭字段,不然爲服務器名稱。 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for ; proxy_set_header Accept-Encoding ""; proxy_set_header X-Real-IP $remote_addr; add_header 'Access-Control-Allow-Origin' '*'; proxy_pass http://xxxxx.com:8000/restful/; } location /wqgl/ { proxy_redirect off; proxy_pass http://xxxxx.com:3001/; } # location / { # try_files $uri $uri/ =404; # } } } #mail { # # See sample authentication script at: # # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript # # # auth_http localhost/auth.php; # # pop3_capabilities "TOP" "USER"; # # imap_capabilities "IMAP4rev1" "UIDPLUS"; # # server { # listen localhost:110; # protocol pop3; # proxy on; # } # # server { # listen localhost:143; # protocol imap; # proxy on; # } #}
切記 proxy_pass http://xxxxx.com:3001/,最後的"/"必須加上。